Note: Using Return.portfolio() does NOT include
transaction costs, nor does it produce an Optimal portfolio.
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
port1<-Return.portfolio(R=Returns, verbose = TRUE)
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
wF = .05
wGE = .25
wCAT = .70
startingweights<-c(wF,wGE,wCAT)
port1<-Return.portfolio(R=Returns, weights = startingweights, verbose = TRUE)
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
library(PerformanceAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
wF = -.05
wGE = .25
wCAT = .8
startingweights<-c(wF,wGE,wCAT)
port1<-Return.portfolio(R=Returns, weights = startingweights, verbose = TRUE)
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
wF = .05
wGE = .25
wCAT = 1-wF-wGE
startingweights<-c(wF,wGE,wCAT)
port1<-Return.portfolio(R=Returns, weights = startingweights, verbose = TRUE)
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
weightmatrix<-Returns #stealing the data type and dates
T = dim(weightmatrix)[1] #Number of days
wF = .05
wGE = .25
wCAT = .70
weightmatrix$F<-rep(wF,T)
weightmatrix$GE<-rep(wGE,T)
weightmatrix$CAT<-rep(wCAT,T)
weightmatrix$GE<-rep(.05,dim(weightmatrix$GE)[1]) # change a weight arbitrarily for this example
weightmatrix$CAT<-1-rowSums(weightmatrix[,-3]) # "-3" uses CAT to ensure the portfolio is always fully invested
head(weightmatrix)
## F GE CAT
## 2015-01-05 0.05 0.05 0.9
## 2015-01-06 0.05 0.05 0.9
## 2015-01-07 0.05 0.05 0.9
## 2015-01-08 0.05 0.05 0.9
## 2015-01-09 0.05 0.05 0.9
## 2015-01-12 0.05 0.05 0.9
port1<-Return.portfolio(R=Returns, weights = weightmatrix, verbose = TRUE)
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
port1<-Return.portfolio(R=Returns, verbose = TRUE)
StartingEquity = 1 # change to whatever value you like
port1$GrossReturns<-port1$returns+1
port1$GrossReturns[1,1]=StartingEquity
colnames(port1$GrossReturns)<- "GrossReturns"
port1$PortfolioIndex=cumprod(port1$GrossReturns)
colnames(port1$PortfolioIndex)<- "PortfolioIndex"
tail(port1$PortfolioIndex)
## PortfolioIndex
## 2021-04-22 1.632678
## 2021-04-23 1.653915
## 2021-04-26 1.657846
## 2021-04-27 1.662295
## 2021-04-28 1.664662
## 2021-04-29 1.606665
chart.TimeSeries(port1$PortfolioIndex)
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
port1<-Return.portfolio(R=Returns, verbose = TRUE)
chart.CumReturns(port1$returns)
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
port1<-Return.portfolio(R=Returns, verbose = TRUE)
chart.Drawdown(port1$returns)
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
port1<-Return.portfolio(R=Returns, verbose = TRUE)
charts.PerformanceSummary(port1$returns)
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
port1<-Return.portfolio(R=Returns, verbose = TRUE)
chart.StackedBar(port1$BOP.Weight["/2015-02-28",])
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
port1<-Return.portfolio(R=Returns, verbose = TRUE)
LastWeight = data.matrix(tail(port1$EOP.Weight,n=1))
pie(LastWeight,Tickers)
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
port1<-Return.portfolio(R=Returns, verbose = TRUE)
chart.TimeSeries(port1$contribution,legend.loc = 'bottomright')
Contributions<-cumsum(port1$contribution)
chart.TimeSeries(Contributions,legend.loc = 'topleft')
Note: Using Return.portfolio does NOT include transaction costs, nor does it produce an Optimal portfolio. Can alter rebalance_on to (days,weeks,months,quarters,years).
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
library(PerformanceAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
wF = .05
wGE = .25
wCAT = .70
startingweights<-c(wF,wGE,wCAT)
port1<-Return.portfolio(R=Returns, weights = startingweights, rebalance_on = "days", verbose = TRUE)
head(port1$BOP.Weight)
## daily.returns daily.returns.1 daily.returns.2
## 2015-01-05 0.05 0.25 0.7
## 2015-01-06 0.05 0.25 0.7
## 2015-01-07 0.05 0.25 0.7
## 2015-01-08 0.05 0.25 0.7
## 2015-01-09 0.05 0.25 0.7
## 2015-01-12 0.05 0.25 0.7
head(port1$EOP.Weight)
## daily.returns daily.returns.1 daily.returns.2
## 2015-01-05 0.05023157 0.2565698 0.6931986
## 2015-01-06 0.05004443 0.2471757 0.7027799
## 2015-01-07 0.05080701 0.2470435 0.7021494
## 2015-01-08 0.05068304 0.2501469 0.6991701
## 2015-01-09 0.04994504 0.2496409 0.7004140
## 2015-01-12 0.05036309 0.2511264 0.6985105
You can control the precise date of rebalancing by defining a weight matrix that contains the weights for each period on every ticker.
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PortfolioAnalytics)
Tickers<-c('F','GE','CAT')
startd = "2015-01-01"
endd = "2021-04-30"
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "F" "GE" "CAT"
Prices = do.call(merge,lapply(Tickers, function(x) Ad(get(x))))
Prices = na.omit(Prices[-1,])
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-names(Prices)
weightmatrix<-Returns #stealing the data type and dates
T = dim(weightmatrix)[1] #Number of days
wF = .05
wGE = .25
wCAT = .70
weightmatrix$F.Adjusted<-rep(wF,T)
weightmatrix$GE.Adjusted<-rep(wGE,T)
weightmatrix$CAT.Adjusted<-rep(wCAT,T)
port1<-Return.portfolio(R=Returns, weights = weightmatrix, verbose = TRUE)
head(port1$BOP.Weight)
## F.Adjusted GE.Adjusted CAT.Adjusted
## 2015-01-06 0.05 0.25 0.7
## 2015-01-07 0.05 0.25 0.7
## 2015-01-08 0.05 0.25 0.7
## 2015-01-09 0.05 0.25 0.7
## 2015-01-12 0.05 0.25 0.7
## 2015-01-13 0.05 0.25 0.7
Minimum Variance, Subject to Target Return, Fully Invested, Long Only
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
### Construct Portfolio
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Returns))
# Add a target return constraint
init.portf <- add.constraint(portfolio=init.portf, type="return", return_target=0.001)
# Add a full investment constraint such that the weights sum to 1
init.portf <- add.constraint(portfolio=init.portf, type="full_investment")
# Add a long only constraint such that the weight of an asset is between 0 and 1
init.portf <- add.constraint(portfolio=init.portf, type="long_only")
# Add objective to minimize portfolio variance
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "var")
### Solve Portfolio: Minimize Variance
library(ROI)
opt.MinVar <- optimize.portfolio(R=Returns,
portfolio=init.portf,
optimize_method="ROI",
trace=TRUE)
summary(opt.MinVar) # The optimization summary should be read carefully since not every constraint is guaranteed to be satisfied
## **************************************************
## PortfolioAnalytics Optimization Summary
## **************************************************
##
## Call:
## optimize.portfolio(R = Returns, portfolio = init.portf, optimize_method = "ROI",
## trace = TRUE)
##
## Optimal Weights:
## IBM GE F MSFT
## 0.1718 0.0000 0.0972 0.7310
##
## Objective Measures:
## StdDev
## 0.01529
##
##
## Portfolio Assets and Initial Weights:
## IBM GE F MSFT
## 0.25 0.25 0.25 0.25
##
## **************************************************
## PortfolioAnalytics Portfolio Specification
## **************************************************
##
## Call:
## portfolio.spec(assets = colnames(Returns))
##
## Number of assets: 4
## Asset Names
## [1] "IBM" "GE" "F" "MSFT"
##
## Constraints
## Enabled constraint types
## - return
## - full_investment
## - long_only
##
## Objectives:
## Enabled objective names
## - var
##
## ****************************************
## Constraints
## ****************************************
## Leverage Constraint:
## min_sum = 1
## max_sum = 1
## actual_leverage = 1
##
## Box Constraints:
## min:
## IBM GE F MSFT
## 0 0 0 0
## max:
## IBM GE F MSFT
## 1 1 1 1
##
## Position Limit Constraints:
## Maximum number of non-zero weights, max_pos:
## [1] "Unconstrained"
## Realized number of non-zero weights (i.e. positions):
## [1] 3
##
## Maximum number of long positions, max_pos_long:
## [1] "Unconstrained"
## Realized number of long positions:
## [1] 3
##
## Maximum number of short positions, max_pos_short:
## [1] "Unconstrained"
## Realized number of short positions:
## [1] 0
##
##
## Diversification Target Constraint:
## [1] "Unconstrained"
##
## Realized diversification:
## [1] 0.426643
##
## Turnover Target Constraint:
## [1] "Unconstrained"
##
## Realized turnover from initial weights:
## [1] 0.2405153
##
## ****************************************
## Objectives
## ****************************************
##
## Objective: portfolio_risk_objective
## $name
## [1] "var"
##
## $target
## NULL
##
## $arguments
## $arguments$portfolio_method
## [1] "single"
##
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] 1
##
## $call
## add.objective(portfolio = init.portf, type = "risk", name = "var")
##
## attr(,"class")
## [1] "portfolio_risk_objective" "objective"
##
## ****************************************
##
## Elapsed Time:
## Time difference of 0.03888774 secs
### Visualize result
library(PerformanceAnalytics)
# Optimal weights
OptWeight = extractWeights(opt.MinVar)
sum(OptWeight)
## [1] 1
chart.Weights(opt.MinVar)
# Portfolio returns
PortReturn <- Return.portfolio(R = Returns,
weights = OptWeight,
geometric = FALSE) #use arithmetic(FALSE) to aggregate returns
chart.TimeSeries(PortReturn)
mean(PortReturn)
## [1] 0.001
# Variance
var(PortReturn)
## portfolio.returns
## portfolio.returns 0.0002338935
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
### Construct Portfolio
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Returns))
# Add a target return constraint
init.portf <- add.constraint(portfolio=init.portf, type="return", return_target=0.001)
# Add a full investment constraint such that the weights sum to 1
init.portf <- add.constraint(portfolio=init.portf, type="full_investment")
# Add objective to minimize portfolio variance
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "var")
### Solve Portfolio: Minimize Variance
library(ROI)
opt.MinVar <- optimize.portfolio(R=Returns,
portfolio=init.portf,
optimize_method="ROI",
trace=TRUE)
summary(opt.MinVar) # The optimization summary should be read carefully since not every constraint is guaranteed to be satisfied
## **************************************************
## PortfolioAnalytics Optimization Summary
## **************************************************
##
## Call:
## optimize.portfolio(R = Returns, portfolio = init.portf, optimize_method = "ROI",
## trace = TRUE)
##
## Optimal Weights:
## IBM GE F MSFT
## 0.1923 -0.0286 0.1114 0.7249
##
## Objective Measures:
## StdDev
## 0.01528
##
##
## Portfolio Assets and Initial Weights:
## IBM GE F MSFT
## 0.25 0.25 0.25 0.25
##
## **************************************************
## PortfolioAnalytics Portfolio Specification
## **************************************************
##
## Call:
## portfolio.spec(assets = colnames(Returns))
##
## Number of assets: 4
## Asset Names
## [1] "IBM" "GE" "F" "MSFT"
##
## Constraints
## Enabled constraint types
## - return
## - full_investment
##
## Objectives:
## Enabled objective names
## - var
##
## ****************************************
## Constraints
## ****************************************
## Leverage Constraint:
## min_sum = 1
## max_sum = 1
## actual_leverage = 1
##
## Box Constraints:
## min:
## [1] -Inf -Inf -Inf -Inf
## max:
## [1] Inf Inf Inf Inf
##
## Position Limit Constraints:
## Maximum number of non-zero weights, max_pos:
## [1] "Unconstrained"
## Realized number of non-zero weights (i.e. positions):
## [1] 4
##
## Maximum number of long positions, max_pos_long:
## [1] "Unconstrained"
## Realized number of long positions:
## [1] 3
##
## Maximum number of short positions, max_pos_short:
## [1] "Unconstrained"
## Realized number of short positions:
## [1] 1
##
##
## Diversification Target Constraint:
## [1] "Unconstrained"
##
## Realized diversification:
## [1] 0.4243172
##
## Turnover Target Constraint:
## [1] "Unconstrained"
##
## Realized turnover from initial weights:
## [1] 0.2374474
##
## ****************************************
## Objectives
## ****************************************
##
## Objective: portfolio_risk_objective
## $name
## [1] "var"
##
## $target
## NULL
##
## $arguments
## $arguments$portfolio_method
## [1] "single"
##
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] 1
##
## $call
## add.objective(portfolio = init.portf, type = "risk", name = "var")
##
## attr(,"class")
## [1] "portfolio_risk_objective" "objective"
##
## ****************************************
##
## Elapsed Time:
## Time difference of 0.009923935 secs
### Visualize result
library(PerformanceAnalytics)
# Optimal weights
OptWeight = extractWeights(opt.MinVar)
sum(OptWeight)
## [1] 1
chart.Weights(opt.MinVar)
# Portfolio returns
PortReturn <- Return.portfolio(R = Returns,
weights = OptWeight,
geometric = FALSE) #use arithmetic(FALSE) to aggregate returns
chart.TimeSeries(PortReturn)
mean(PortReturn)
## [1] 0.001
# Variance
var(PortReturn)
## portfolio.returns
## portfolio.returns 0.0002335735
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
### Construct Portfolio
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Returns))
# Add a full investment constraint such that the weights sum to 1
init.portf <- add.constraint(portfolio=init.portf, type="full_investment")
# Add risk and return objective(we need them to calculate the Sharpe ratio)
init.portf <- add.objective(portfolio=init.portf, type="return", name = "mean")
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "StdDev")
### Solve Portfolio
library(ROI)
opt <- optimize.portfolio(R=Returns,
portfolio=init.portf,
optimize_method="ROI",
maxSR=TRUE,
trace=TRUE)
summary(opt) # The optimization summary should be read carefully since not every constraint is guaranteed to be satisfied
## **************************************************
## PortfolioAnalytics Optimization Summary
## **************************************************
##
## Call:
## optimize.portfolio(R = Returns, portfolio = init.portf, optimize_method = "ROI",
## trace = TRUE, maxSR = TRUE)
##
## Optimal Weights:
## IBM GE F MSFT
## 0.0218 -0.0804 0.0757 0.9830
##
## Objective Measures:
## StdDev
## 0.01733
##
##
## mean
## 0.001288
##
##
## Portfolio Assets and Initial Weights:
## IBM GE F MSFT
## 0.25 0.25 0.25 0.25
##
## **************************************************
## PortfolioAnalytics Portfolio Specification
## **************************************************
##
## Call:
## portfolio.spec(assets = colnames(Returns))
##
## Number of assets: 4
## Asset Names
## [1] "IBM" "GE" "F" "MSFT"
##
## Constraints
## Enabled constraint types
## - full_investment
##
## Objectives:
## Enabled objective names
## - mean
## - StdDev
##
## ****************************************
## Constraints
## ****************************************
## Leverage Constraint:
## min_sum = 1
## max_sum = 1
## actual_leverage = 1
##
## Box Constraints:
## min:
## [1] -Inf -Inf -Inf -Inf
## max:
## [1] Inf Inf Inf Inf
##
## Position Limit Constraints:
## Maximum number of non-zero weights, max_pos:
## [1] "Unconstrained"
## Realized number of non-zero weights (i.e. positions):
## [1] 4
##
## Maximum number of long positions, max_pos_long:
## [1] "Unconstrained"
## Realized number of long positions:
## [1] 3
##
## Maximum number of short positions, max_pos_short:
## [1] "Unconstrained"
## Realized number of short positions:
## [1] 1
##
##
## Diversification Target Constraint:
## [1] "Unconstrained"
##
## Realized diversification:
## [1] 0.02113154
##
## Turnover Target Constraint:
## [1] "Unconstrained"
##
## Realized turnover from initial weights:
## [1] 0.3664756
##
## ****************************************
## Objectives
## ****************************************
##
## Objective: return_objective
## $name
## [1] "mean"
##
## $target
## NULL
##
## $arguments
## list()
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] -1
##
## $call
## add.objective(portfolio = init.portf, type = "return", name = "mean")
##
## attr(,"class")
## [1] "return_objective" "objective"
##
## ****************************************
## Objective: portfolio_risk_objective
## $name
## [1] "StdDev"
##
## $target
## NULL
##
## $arguments
## $arguments$portfolio_method
## [1] "single"
##
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] 1
##
## $call
## add.objective(portfolio = init.portf, type = "risk", name = "StdDev")
##
## attr(,"class")
## [1] "portfolio_risk_objective" "objective"
##
## ****************************************
##
## Elapsed Time:
## Time difference of 0.2770972 secs
### Visualize result
library(PerformanceAnalytics)
# Optimal weights
OptWeight = extractWeights(opt)
sum(OptWeight)
## [1] 1
chart.Weights(opt)
# Portfolio returns
PortReturn <- Return.portfolio(R = Returns,
weights = OptWeight,
geometric = FALSE) #use arithmetic(FALSE) to aggregate returns
chart.TimeSeries(PortReturn)
mean(PortReturn)
## [1] 0.001287984
# Variance
var(PortReturn)
## portfolio.returns
## portfolio.returns 0.0003003911
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
### Construct Portfolio
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Returns))
# Add a full investment constraint such that the weights sum to 1
init.portf <- add.constraint(portfolio=init.portf, type="full_investment")
# Add risk and return objective(we need them to calculate the Sharpe ratio)
init.portf <- add.objective(portfolio=init.portf, type="return", name = "mean")
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "StdDev")
### Solve Portfolio
library(ROI)
opt <- optimize.portfolio(R=Returns,
portfolio=init.portf,
optimize_method="ROI",
maxSR=TRUE,
trace=TRUE)
summary(opt) # The optimization summary should be read carefully since not every constraint is guaranteed to be satisfied
## **************************************************
## PortfolioAnalytics Optimization Summary
## **************************************************
##
## Call:
## optimize.portfolio(R = Returns, portfolio = init.portf, optimize_method = "ROI",
## trace = TRUE, maxSR = TRUE)
##
## Optimal Weights:
## IBM GE F MSFT
## 0.0218 -0.0804 0.0757 0.9830
##
## Objective Measures:
## StdDev
## 0.01733
##
##
## mean
## 0.001288
##
##
## Portfolio Assets and Initial Weights:
## IBM GE F MSFT
## 0.25 0.25 0.25 0.25
##
## **************************************************
## PortfolioAnalytics Portfolio Specification
## **************************************************
##
## Call:
## portfolio.spec(assets = colnames(Returns))
##
## Number of assets: 4
## Asset Names
## [1] "IBM" "GE" "F" "MSFT"
##
## Constraints
## Enabled constraint types
## - full_investment
##
## Objectives:
## Enabled objective names
## - mean
## - StdDev
##
## ****************************************
## Constraints
## ****************************************
## Leverage Constraint:
## min_sum = 1
## max_sum = 1
## actual_leverage = 1
##
## Box Constraints:
## min:
## [1] -Inf -Inf -Inf -Inf
## max:
## [1] Inf Inf Inf Inf
##
## Position Limit Constraints:
## Maximum number of non-zero weights, max_pos:
## [1] "Unconstrained"
## Realized number of non-zero weights (i.e. positions):
## [1] 4
##
## Maximum number of long positions, max_pos_long:
## [1] "Unconstrained"
## Realized number of long positions:
## [1] 3
##
## Maximum number of short positions, max_pos_short:
## [1] "Unconstrained"
## Realized number of short positions:
## [1] 1
##
##
## Diversification Target Constraint:
## [1] "Unconstrained"
##
## Realized diversification:
## [1] 0.02113156
##
## Turnover Target Constraint:
## [1] "Unconstrained"
##
## Realized turnover from initial weights:
## [1] 0.3664756
##
## ****************************************
## Objectives
## ****************************************
##
## Objective: return_objective
## $name
## [1] "mean"
##
## $target
## NULL
##
## $arguments
## list()
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] -1
##
## $call
## add.objective(portfolio = init.portf, type = "return", name = "mean")
##
## attr(,"class")
## [1] "return_objective" "objective"
##
## ****************************************
## Objective: portfolio_risk_objective
## $name
## [1] "StdDev"
##
## $target
## NULL
##
## $arguments
## $arguments$portfolio_method
## [1] "single"
##
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] 1
##
## $call
## add.objective(portfolio = init.portf, type = "risk", name = "StdDev")
##
## attr(,"class")
## [1] "portfolio_risk_objective" "objective"
##
## ****************************************
##
## Elapsed Time:
## Time difference of 0.2745883 secs
### Visualize result
library(PerformanceAnalytics)
# Optimal weights
OptWeight = extractWeights(opt)
sum(OptWeight)
## [1] 1
chart.Weights(opt)
# Portfolio returns
PortReturn <- Return.portfolio(R = Returns,
weights = OptWeight,
geometric = FALSE) #use arithmetic(FALSE) to aggregate returns
chart.TimeSeries(PortReturn)
mean(PortReturn)
## [1] 0.001287984
# Variance
var(PortReturn)
## portfolio.returns
## portfolio.returns 0.0003003909
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
### Construct Portfolio
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Returns))
# Add a full investment constraint such that the weights sum to 1
init.portf <- add.constraint(portfolio=init.portf, type="full_investment")
# Add upper and lower bounds on the weights of assets
init.portf <- add.constraint(portfolio=init.portf, type="box", min=0, max=0.5)
# Add risk and return objective(we need them to calculate the Sharpe ratio)
init.portf <- add.objective(portfolio=init.portf, type="return", name = "mean")
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "StdDev")
### Solve Portfolio
library(ROI)
opt <- optimize.portfolio(R=Returns,
portfolio=init.portf,
optimize_method="ROI",
maxSR=TRUE,
trace=TRUE)
summary(opt) # The optimization summary should be read carefully since not every constraint is guaranteed to be satisfied
## **************************************************
## PortfolioAnalytics Optimization Summary
## **************************************************
##
## Call:
## optimize.portfolio(R = Returns, portfolio = init.portf, optimize_method = "ROI",
## trace = TRUE, maxSR = TRUE)
##
## Optimal Weights:
## IBM GE F MSFT
## 0.3541 0.0000 0.1459 0.5000
##
## Objective Measures:
## StdDev
## 0.01426
##
##
## mean
## 0.0007529
##
##
## Portfolio Assets and Initial Weights:
## IBM GE F MSFT
## 0.25 0.25 0.25 0.25
##
## **************************************************
## PortfolioAnalytics Portfolio Specification
## **************************************************
##
## Call:
## portfolio.spec(assets = colnames(Returns))
##
## Number of assets: 4
## Asset Names
## [1] "IBM" "GE" "F" "MSFT"
##
## Constraints
## Enabled constraint types
## - full_investment
## - box
##
## Objectives:
## Enabled objective names
## - mean
## - StdDev
##
## ****************************************
## Constraints
## ****************************************
## Leverage Constraint:
## min_sum = 1
## max_sum = 1
## actual_leverage = 1
##
## Box Constraints:
## min:
## IBM GE F MSFT
## 0 0 0 0
## max:
## IBM GE F MSFT
## 0.5 0.5 0.5 0.5
##
## Position Limit Constraints:
## Maximum number of non-zero weights, max_pos:
## [1] "Unconstrained"
## Realized number of non-zero weights (i.e. positions):
## [1] 3
##
## Maximum number of long positions, max_pos_long:
## [1] "Unconstrained"
## Realized number of long positions:
## [1] 3
##
## Maximum number of short positions, max_pos_short:
## [1] "Unconstrained"
## Realized number of short positions:
## [1] 0
##
##
## Diversification Target Constraint:
## [1] "Unconstrained"
##
## Realized diversification:
## [1] 0.6033234
##
## Turnover Target Constraint:
## [1] "Unconstrained"
##
## Realized turnover from initial weights:
## [1] 0.1770536
##
## ****************************************
## Objectives
## ****************************************
##
## Objective: return_objective
## $name
## [1] "mean"
##
## $target
## NULL
##
## $arguments
## list()
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] -1
##
## $call
## add.objective(portfolio = init.portf, type = "return", name = "mean")
##
## attr(,"class")
## [1] "return_objective" "objective"
##
## ****************************************
## Objective: portfolio_risk_objective
## $name
## [1] "StdDev"
##
## $target
## NULL
##
## $arguments
## $arguments$portfolio_method
## [1] "single"
##
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] 1
##
## $call
## add.objective(portfolio = init.portf, type = "risk", name = "StdDev")
##
## attr(,"class")
## [1] "portfolio_risk_objective" "objective"
##
## ****************************************
##
## Elapsed Time:
## Time difference of 0.202183 secs
### Visualize result
library(PerformanceAnalytics)
# Optimal weights
OptWeight = extractWeights(opt)
sum(OptWeight)
## [1] 1
chart.Weights(opt)
# Portfolio returns
PortReturn <- Return.portfolio(R = Returns,
weights = OptWeight,
geometric = FALSE) #use arithmetic(FALSE) to aggregate returns
chart.TimeSeries(PortReturn)
mean(PortReturn)
## [1] 0.0007528538
# Variance
var(PortReturn)
## portfolio.returns
## portfolio.returns 0.0002033752
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
### Construct Portfolio
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Returns))
# Add a full investment constraint such that the weights sum to 1
init.portf <- add.constraint(portfolio=init.portf, type="full_investment")
# Add position limit constraint such that we have a maximum number of long positions and short positions
init.portf <- add.constraint(portfolio=init.portf,
type="position_limit",
max_pos_long = 3,
max_pos_short = 2)
# Add risk and return objective(we need them to calculate the Sharpe ratio)
init.portf <- add.objective(portfolio=init.portf, type="return", name = "mean")
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "StdDev")
### Solve Portfolio
library(ROI)
opt <- optimize.portfolio(R=Returns,
portfolio=init.portf,
optimize_method="ROI",
maxSR=TRUE,
trace=TRUE)
summary(opt) # The optimization summary should be read carefully since not every constraint is guaranteed to be satisfied
## **************************************************
## PortfolioAnalytics Optimization Summary
## **************************************************
##
## Call:
## optimize.portfolio(R = Returns, portfolio = init.portf, optimize_method = "ROI",
## trace = TRUE, maxSR = TRUE)
##
## Optimal Weights:
## IBM GE F MSFT
## 0.0218 -0.0804 0.0757 0.9830
##
## Objective Measures:
## StdDev
## 0.01733
##
##
## mean
## 0.001288
##
##
## Portfolio Assets and Initial Weights:
## IBM GE F MSFT
## 0.25 0.25 0.25 0.25
##
## **************************************************
## PortfolioAnalytics Portfolio Specification
## **************************************************
##
## Call:
## portfolio.spec(assets = colnames(Returns))
##
## Number of assets: 4
## Asset Names
## [1] "IBM" "GE" "F" "MSFT"
##
## Constraints
## Enabled constraint types
## - full_investment
## - position_limit
##
## Objectives:
## Enabled objective names
## - mean
## - StdDev
##
## ****************************************
## Constraints
## ****************************************
## Leverage Constraint:
## min_sum = 1
## max_sum = 1
## actual_leverage = 1
##
## Box Constraints:
## min:
## [1] -Inf -Inf -Inf -Inf
## max:
## [1] Inf Inf Inf Inf
##
## Position Limit Constraints:
## Maximum number of non-zero weights, max_pos:
## [1] "Unconstrained"
## Realized number of non-zero weights (i.e. positions):
## [1] 4
##
## Maximum number of long positions, max_pos_long:
## [1] 3
## Realized number of long positions:
## [1] 3
##
## Maximum number of short positions, max_pos_short:
## [1] 2
## Realized number of short positions:
## [1] 1
##
##
## Diversification Target Constraint:
## [1] "Unconstrained"
##
## Realized diversification:
## [1] 0.02113154
##
## Turnover Target Constraint:
## [1] "Unconstrained"
##
## Realized turnover from initial weights:
## [1] 0.3664756
##
## ****************************************
## Objectives
## ****************************************
##
## Objective: return_objective
## $name
## [1] "mean"
##
## $target
## NULL
##
## $arguments
## list()
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] -1
##
## $call
## add.objective(portfolio = init.portf, type = "return", name = "mean")
##
## attr(,"class")
## [1] "return_objective" "objective"
##
## ****************************************
## Objective: portfolio_risk_objective
## $name
## [1] "StdDev"
##
## $target
## NULL
##
## $arguments
## $arguments$portfolio_method
## [1] "single"
##
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] 1
##
## $call
## add.objective(portfolio = init.portf, type = "risk", name = "StdDev")
##
## attr(,"class")
## [1] "portfolio_risk_objective" "objective"
##
## ****************************************
##
## Elapsed Time:
## Time difference of 0.2668672 secs
### Visualize result
library(PerformanceAnalytics)
# Optimal weights
OptWeight = extractWeights(opt)
sum(OptWeight)
## [1] 1
chart.Weights(opt)
# Portfolio returns
PortReturn <- Return.portfolio(R = Returns,
weights = OptWeight,
geometric = FALSE) #use arithmetic(FALSE) to aggregate returns
chart.TimeSeries(PortReturn)
mean(PortReturn)
## [1] 0.001287984
# Variance
var(PortReturn)
## portfolio.returns
## portfolio.returns 0.0003003908
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Return = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Return = na.omit(Return[-1,])
colnames(Return)<-Tickers
### Estimate Market Risk Exposure(assume Rf = 0)
# Load market data(we need this because we want it to calculate the market risk exposure)
getSymbols("^GSPC", from = startd, to = endd)
## [1] "^GSPC"
SP500 <- periodReturn(Ad(get("GSPC")),period='daily',type='arithmetic')
na.omit(SP500)
## daily.returns
## 2015-01-02 0.000000e+00
## 2015-01-05 -1.827811e-02
## 2015-01-06 -8.893472e-03
## 2015-01-07 1.162984e-02
## 2015-01-08 1.788828e-02
## 2015-01-09 -8.403811e-03
## 2015-01-12 -8.093685e-03
## 2015-01-13 -2.578555e-03
## 2015-01-14 -5.813067e-03
## 2015-01-15 -9.247876e-03
## 2015-01-16 1.342420e-02
## 2015-01-20 1.549952e-03
## 2015-01-21 4.731624e-03
## 2015-01-22 1.526972e-02
## 2015-01-23 -5.491522e-03
## 2015-01-26 2.568461e-03
## 2015-01-27 -1.338786e-02
## 2015-01-28 -1.349561e-02
## 2015-01-29 9.534685e-03
## 2015-01-30 -1.299197e-02
## 2015-02-02 1.296246e-02
## 2015-02-03 1.443949e-02
## 2015-02-04 -4.156046e-03
## 2015-02-05 1.029141e-02
## 2015-02-06 -3.418172e-03
## 2015-02-09 -4.247195e-03
## 2015-02-10 1.067556e-02
## 2015-02-11 -2.903379e-05
## 2015-02-12 9.644506e-03
## 2015-02-13 4.074739e-03
## 2015-02-17 1.597575e-03
## 2015-02-18 -3.143091e-04
## 2015-02-19 -1.062058e-03
## 2015-02-20 6.126534e-03
## 2015-02-23 -3.033393e-04
## 2015-02-24 2.758771e-03
## 2015-02-25 -7.657236e-04
## 2015-02-26 -1.476028e-03
## 2015-02-27 -2.956304e-03
## 2015-03-02 6.124919e-03
## 2015-03-03 -4.538542e-03
## 2015-03-04 -4.388503e-03
## 2015-03-05 1.196080e-03
## 2015-03-06 -1.417395e-02
## 2015-03-09 3.944421e-03
## 2015-03-10 -1.696133e-02
## 2015-03-11 -1.917680e-03
## 2015-03-12 1.260144e-02
## 2015-03-13 -6.074711e-03
## 2015-03-16 1.353367e-02
## 2015-03-17 -3.320174e-03
## 2015-03-18 1.215842e-02
## 2015-03-19 -4.872579e-03
## 2015-03-20 9.012755e-03
## 2015-03-23 -1.745731e-03
## 2015-03-24 -6.139422e-03
## 2015-03-25 -1.455891e-02
## 2015-03-26 -2.377500e-03
## 2015-03-27 2.368562e-03
## 2015-03-30 1.223664e-02
## 2015-03-31 -8.795775e-03
## 2015-04-01 -3.965372e-03
## 2015-04-02 3.529667e-03
## 2015-04-06 6.608815e-03
## 2015-04-07 -2.061904e-03
## 2015-04-08 2.682533e-03
## 2015-04-09 4.457481e-03
## 2015-04-10 5.202865e-03
## 2015-04-13 -4.581281e-03
## 2015-04-14 1.629759e-03
## 2015-04-15 5.148196e-03
## 2015-04-16 -7.784438e-04
## 2015-04-17 -1.131125e-02
## 2015-04-20 9.235131e-03
## 2015-04-21 -1.480605e-03
## 2015-04-22 5.087480e-03
## 2015-04-23 2.357716e-03
## 2015-04-24 2.252800e-03
## 2015-04-27 -4.141314e-03
## 2015-04-28 2.769232e-03
## 2015-04-29 -3.740336e-03
## 2015-04-30 -1.012891e-02
## 2015-05-01 1.092300e-02
## 2015-05-04 2.940749e-03
## 2015-05-05 -1.183738e-02
## 2015-05-06 -4.455725e-03
## 2015-05-07 3.773814e-03
## 2015-05-08 1.345790e-02
## 2015-05-11 -5.089561e-03
## 2015-05-12 -2.949638e-03
## 2015-05-13 -3.049549e-04
## 2015-05-14 1.077929e-02
## 2015-05-15 7.684135e-04
## 2015-05-18 3.047948e-03
## 2015-05-19 -6.433745e-04
## 2015-05-20 -9.305160e-04
## 2015-05-21 2.337874e-03
## 2015-05-22 -2.233886e-03
## 2015-05-26 -1.028198e-02
## 2015-05-27 9.162641e-03
## 2015-05-28 -1.266761e-03
## 2015-05-29 -6.318469e-03
## 2015-06-01 2.059461e-03
## 2015-06-02 -1.008596e-03
## 2015-06-03 2.118871e-03
## 2015-06-04 -8.623167e-03
## 2015-06-05 -1.436183e-03
## 2015-06-08 -6.474510e-03
## 2015-06-09 4.183530e-04
## 2015-06-10 1.204242e-02
## 2015-06-11 1.738626e-03
## 2015-06-12 -6.994300e-03
## 2015-06-15 -4.622572e-03
## 2015-06-16 5.689856e-03
## 2015-06-17 1.979641e-03
## 2015-06-18 9.902711e-03
## 2015-06-19 -5.303502e-03
## 2015-06-22 6.094867e-03
## 2015-06-23 6.358683e-04
## 2015-06-24 -7.353297e-03
## 2015-06-25 -2.973574e-03
## 2015-06-26 -3.900799e-04
## 2015-06-29 -2.086619e-02
## 2015-06-30 2.658489e-03
## 2015-07-01 6.936040e-03
## 2015-07-02 -3.080229e-04
## 2015-07-06 -3.861757e-03
## 2015-07-07 6.080975e-03
## 2015-07-08 -1.665275e-02
## 2015-07-09 2.262203e-03
## 2015-07-10 1.233848e-02
## 2015-07-13 1.106605e-02
## 2015-07-14 4.453159e-03
## 2015-07-15 -7.349861e-04
## 2015-07-16 8.014681e-03
## 2015-07-17 1.106183e-03
## 2015-07-20 7.712335e-04
## 2015-07-21 -4.261689e-03
## 2015-07-22 -2.387710e-03
## 2015-07-23 -5.676040e-03
## 2015-07-24 -1.070333e-02
## 2015-07-27 -5.775015e-03
## 2015-07-28 1.238615e-02
## 2015-07-29 7.318795e-03
## 2015-07-30 2.836757e-05
## 2015-07-31 -2.271520e-03
## 2015-08-03 -2.756887e-03
## 2015-08-04 -2.249705e-03
## 2015-08-05 3.114679e-03
## 2015-08-06 -7.752985e-03
## 2015-08-07 -2.874883e-03
## 2015-08-10 1.280817e-02
## 2015-08-11 -9.557103e-03
## 2015-08-12 9.500549e-04
## 2015-08-13 -1.275212e-03
## 2015-08-14 3.911964e-03
## 2015-08-17 5.211424e-03
## 2015-08-18 -2.625530e-03
## 2015-08-19 -8.254877e-03
## 2015-08-20 -2.110017e-02
## 2015-08-21 -3.185097e-02
## 2015-08-24 -3.941369e-02
## 2015-08-25 -1.352200e-02
## 2015-08-26 3.903386e-02
## 2015-08-27 2.429775e-02
## 2015-08-28 6.087364e-04
## 2015-08-31 -8.391670e-03
## 2015-09-01 -2.957645e-02
## 2015-09-02 1.829297e-02
## 2015-09-03 1.164794e-03
## 2015-09-04 -1.532960e-02
## 2015-09-08 2.508305e-02
## 2015-09-09 -1.389756e-02
## 2015-09-10 5.277955e-03
## 2015-09-11 4.487043e-03
## 2015-09-14 -4.089656e-03
## 2015-09-15 1.283131e-02
## 2015-09-16 8.705414e-03
## 2015-09-17 -2.561060e-03
## 2015-09-18 -1.616417e-02
## 2015-09-21 4.565784e-03
## 2015-09-22 -1.231843e-02
## 2015-09-23 -2.048643e-03
## 2015-09-24 -3.362985e-03
## 2015-09-25 -4.657931e-04
## 2015-09-28 -2.566609e-02
## 2015-09-29 1.232853e-03
## 2015-09-30 1.907556e-02
## 2015-10-01 1.973884e-03
## 2015-10-02 1.431529e-02
## 2015-10-05 1.828984e-02
## 2015-10-06 -3.588236e-03
## 2015-10-07 8.035634e-03
## 2015-10-08 8.818436e-03
## 2015-10-09 7.251114e-04
## 2015-10-12 1.275477e-03
## 2015-10-13 -6.825424e-03
## 2015-10-14 -4.716274e-03
## 2015-10-15 1.485277e-02
## 2015-10-16 4.570474e-03
## 2015-10-19 2.705456e-04
## 2015-10-20 -1.421090e-03
## 2015-10-21 -5.825415e-03
## 2015-10-22 1.662757e-02
## 2015-10-23 1.103034e-02
## 2015-10-26 -1.913100e-03
## 2015-10-27 -2.554119e-03
## 2015-10-28 1.184003e-02
## 2015-10-29 -4.497744e-04
## 2015-10-30 -4.809877e-03
## 2015-11-02 1.187382e-02
## 2015-11-03 2.728067e-03
## 2015-11-04 -3.545367e-03
## 2015-11-05 -1.132148e-03
## 2015-11-06 -3.476216e-04
## 2015-11-09 -9.822729e-03
## 2015-11-10 1.510595e-03
## 2015-11-11 -3.228086e-03
## 2015-11-12 -1.399038e-02
## 2015-11-13 -1.120736e-02
## 2015-11-16 1.490327e-02
## 2015-11-17 -1.339379e-03
## 2015-11-18 1.616245e-02
## 2015-11-19 -1.123109e-03
## 2015-11-20 3.810196e-03
## 2015-11-23 -1.234861e-03
## 2015-11-24 1.221996e-03
## 2015-11-25 -1.291326e-04
## 2015-11-27 5.936176e-04
## 2015-11-30 -4.640997e-03
## 2015-12-01 1.068057e-02
## 2015-12-02 -1.099569e-02
## 2015-12-03 -1.437353e-02
## 2015-12-04 2.052567e-02
## 2015-12-07 -6.989503e-03
## 2015-12-08 -6.489901e-03
## 2015-12-09 -7.738985e-03
## 2015-12-10 2.251387e-03
## 2015-12-11 -1.942277e-02
## 2015-12-14 4.755560e-03
## 2015-12-15 1.061856e-02
## 2015-12-16 1.451497e-02
## 2015-12-17 -1.504052e-02
## 2015-12-18 -1.779722e-02
## 2015-12-21 7.778402e-03
## 2015-12-22 8.816736e-03
## 2015-12-23 1.241807e-02
## 2015-12-24 -1.598636e-03
## 2015-12-28 -2.178560e-03
## 2015-12-29 1.062976e-02
## 2015-12-30 -7.217229e-03
## 2015-12-31 -9.411913e-03
## 2016-01-04 -1.530373e-02
## 2016-01-05 2.012226e-03
## 2016-01-06 -1.311540e-02
## 2016-01-07 -2.370044e-02
## 2016-01-08 -1.083837e-02
## 2016-01-11 8.532723e-04
## 2016-01-12 7.802799e-03
## 2016-01-13 -2.496545e-02
## 2016-01-14 1.669591e-02
## 2016-01-15 -2.159910e-02
## 2016-01-19 5.318216e-04
## 2016-01-20 -1.169386e-02
## 2016-01-21 5.195438e-03
## 2016-01-22 2.028370e-02
## 2016-01-25 -1.563798e-02
## 2016-01-26 1.414434e-02
## 2016-01-27 -1.086348e-02
## 2016-01-28 5.528577e-03
## 2016-01-29 2.476022e-02
## 2016-02-01 -4.432364e-04
## 2016-02-02 -1.874309e-02
## 2016-02-03 4.992039e-03
## 2016-02-04 1.526733e-03
## 2016-02-05 -1.848125e-02
## 2016-02-08 -1.415394e-02
## 2016-02-09 -6.636201e-04
## 2016-02-10 -1.889505e-04
## 2016-02-11 -1.230116e-02
## 2016-02-12 1.951805e-02
## 2016-02-16 1.651665e-02
## 2016-02-17 1.648044e-02
## 2016-02-18 -4.665714e-03
## 2016-02-19 -2.603307e-05
## 2016-02-22 1.445420e-02
## 2016-02-23 -1.245437e-02
## 2016-02-24 4.439787e-03
## 2016-02-25 1.134828e-02
## 2016-02-26 -1.870114e-03
## 2016-02-29 -8.120977e-03
## 2016-03-01 2.386879e-02
## 2016-03-02 4.094308e-03
## 2016-03-03 3.498741e-03
## 2016-03-04 3.305892e-03
## 2016-03-07 8.850144e-04
## 2016-03-08 -1.124011e-02
## 2016-03-09 5.052393e-03
## 2016-03-10 1.558047e-04
## 2016-03-11 1.639550e-02
## 2016-03-14 -1.260973e-03
## 2016-03-15 -1.836942e-03
## 2016-03-16 5.600352e-03
## 2016-03-17 6.595236e-03
## 2016-03-18 4.405644e-03
## 2016-03-21 9.855775e-04
## 2016-03-22 -8.773879e-04
## 2016-03-23 -6.386032e-03
## 2016-03-24 -3.780705e-04
## 2016-03-28 5.452558e-04
## 2016-03-29 8.816652e-03
## 2016-03-30 4.350315e-03
## 2016-03-31 -2.039759e-03
## 2016-04-01 6.330915e-03
## 2016-04-04 -3.208322e-03
## 2016-04-05 -1.014449e-02
## 2016-04-06 1.050762e-02
## 2016-04-07 -1.197579e-02
## 2016-04-08 2.786578e-03
## 2016-04-11 -2.739786e-03
## 2016-04-12 9.662134e-03
## 2016-04-13 1.004014e-02
## 2016-04-14 1.729272e-04
## 2016-04-15 -9.842849e-04
## 2016-04-18 6.541026e-03
## 2016-04-19 3.084485e-03
## 2016-04-20 7.615446e-04
## 2016-04-21 -5.194027e-03
## 2016-04-22 4.785989e-05
## 2016-04-25 -1.812046e-03
## 2016-04-26 1.872752e-03
## 2016-04-27 1.649353e-03
## 2016-04-28 -9.230768e-03
## 2016-04-29 -5.063088e-03
## 2016-05-02 7.809947e-03
## 2016-05-03 -8.676638e-03
## 2016-05-04 -5.936889e-03
## 2016-05-05 -2.390079e-04
## 2016-05-06 3.174639e-03
## 2016-05-09 7.534966e-04
## 2016-05-10 1.248364e-02
## 2016-05-11 -9.561518e-03
## 2016-05-12 -1.694651e-04
## 2016-05-13 -8.478289e-03
## 2016-05-16 9.796653e-03
## 2016-05-17 -9.411297e-03
## 2016-05-18 2.051788e-04
## 2016-05-19 -3.706708e-03
## 2016-05-20 6.019504e-03
## 2016-05-23 -2.085459e-03
## 2016-05-24 1.368138e-02
## 2016-05-25 6.974740e-03
## 2016-05-26 -2.104437e-04
## 2016-05-27 4.286857e-03
## 2016-05-31 -1.005263e-03
## 2016-06-01 1.135042e-03
## 2016-06-02 2.824678e-03
## 2016-06-03 -2.911815e-03
## 2016-06-06 4.897281e-03
## 2016-06-07 1.289446e-03
## 2016-06-08 3.309566e-03
## 2016-06-09 -1.717759e-03
## 2016-06-10 -9.175181e-03
## 2016-06-13 -8.115191e-03
## 2016-06-14 -1.798886e-03
## 2016-06-15 -1.840713e-03
## 2016-06-16 3.132991e-03
## 2016-06-17 -3.257965e-03
## 2016-06-20 5.808185e-03
## 2016-06-21 2.712061e-03
## 2016-06-22 -1.651564e-03
## 2016-06-23 1.336408e-02
## 2016-06-24 -3.591980e-02
## 2016-06-27 -1.809650e-02
## 2016-06-28 1.777017e-02
## 2016-06-29 1.703267e-02
## 2016-06-30 1.356504e-02
## 2016-07-01 1.948602e-03
## 2016-07-05 -6.847477e-03
## 2016-07-06 5.352963e-03
## 2016-07-07 -8.715778e-04
## 2016-07-08 1.525335e-02
## 2016-07-11 3.408616e-03
## 2016-07-12 7.009293e-03
## 2016-07-13 1.347677e-04
## 2016-07-14 5.259204e-03
## 2016-07-15 -9.289474e-04
## 2016-07-18 2.382295e-03
## 2016-07-19 -1.435174e-03
## 2016-07-20 4.270301e-03
## 2016-07-21 -3.612529e-03
## 2016-07-22 4.553965e-03
## 2016-07-25 -3.011475e-03
## 2016-07-26 3.227846e-04
## 2016-07-27 -1.198542e-03
## 2016-07-28 1.606209e-03
## 2016-07-29 1.631309e-03
## 2016-08-01 -1.269787e-03
## 2016-08-02 -6.361620e-03
## 2016-08-03 3.133943e-03
## 2016-08-04 2.125719e-04
## 2016-08-05 8.603496e-03
## 2016-08-08 -9.071653e-04
## 2016-08-09 3.897936e-04
## 2016-08-10 -2.864686e-03
## 2016-08-11 4.734588e-03
## 2016-08-12 -7.960463e-04
## 2016-08-15 2.792909e-03
## 2016-08-16 -5.479077e-03
## 2016-08-17 1.868590e-03
## 2016-08-18 2.199617e-03
## 2016-08-19 -1.440272e-03
## 2016-08-22 -5.633229e-04
## 2016-08-23 1.951769e-03
## 2016-08-24 -5.240277e-03
## 2016-08-25 -1.365227e-03
## 2016-08-26 -1.578817e-03
## 2016-08-29 5.228047e-03
## 2016-08-30 -1.953681e-03
## 2016-08-31 -2.375864e-03
## 2016-09-01 -4.138465e-05
## 2016-09-02 4.201041e-03
## 2016-09-06 2.981679e-03
## 2016-09-07 -1.463851e-04
## 2016-09-08 -2.223014e-03
## 2016-09-09 -2.452207e-02
## 2016-09-12 1.467705e-02
## 2016-09-13 -1.483067e-02
## 2016-09-14 -5.876767e-04
## 2016-09-15 1.010927e-02
## 2016-09-16 -3.772295e-03
## 2016-09-19 -1.860310e-05
## 2016-09-20 2.991384e-04
## 2016-09-21 1.091716e-02
## 2016-09-22 6.499785e-03
## 2016-09-23 -5.736775e-03
## 2016-09-26 -8.587762e-03
## 2016-09-27 6.444170e-03
## 2016-09-28 5.296554e-03
## 2016-09-29 -9.321411e-03
## 2016-09-30 7.967969e-03
## 2016-10-03 -3.260696e-03
## 2016-10-04 -4.955562e-03
## 2016-10-05 4.296691e-03
## 2016-10-06 4.815602e-04
## 2016-10-07 -3.253484e-03
## 2016-10-10 4.605905e-03
## 2016-10-11 -1.244647e-02
## 2016-10-12 1.146589e-03
## 2016-10-13 -3.099264e-03
## 2016-10-14 2.016042e-04
## 2016-10-17 -3.037994e-03
## 2016-10-18 6.160403e-03
## 2016-10-19 2.191971e-03
## 2016-10-20 -1.375724e-03
## 2016-10-21 -8.414170e-05
## 2016-10-24 4.749840e-03
## 2016-10-25 -3.797728e-03
## 2016-10-26 -1.740411e-03
## 2016-10-27 -2.986727e-03
## 2016-10-28 -3.108299e-03
## 2016-10-31 -1.222765e-04
## 2016-11-01 -6.786883e-03
## 2016-11-02 -6.525501e-03
## 2016-11-03 -4.423401e-03
## 2016-11-04 -1.666131e-03
## 2016-11-07 2.222354e-02
## 2016-11-08 3.771974e-03
## 2016-11-09 1.107702e-02
## 2016-11-10 1.950746e-03
## 2016-11-11 -1.397950e-03
## 2016-11-14 -1.155028e-04
## 2016-11-15 7.480798e-03
## 2016-11-16 -1.582264e-03
## 2016-11-17 4.676370e-03
## 2016-11-18 -2.386798e-03
## 2016-11-21 7.461401e-03
## 2016-11-22 2.165432e-03
## 2016-11-23 8.080248e-04
## 2016-11-25 3.914387e-03
## 2016-11-28 -5.254536e-03
## 2016-11-29 1.335293e-03
## 2016-11-30 -2.653404e-03
## 2016-12-01 -3.515529e-03
## 2016-12-02 3.970065e-04
## 2016-12-05 5.821305e-03
## 2016-12-06 3.410888e-03
## 2016-12-07 1.316324e-02
## 2016-12-08 2.159343e-03
## 2016-12-09 5.938985e-03
## 2016-12-12 -1.137435e-03
## 2016-12-13 6.539775e-03
## 2016-12-14 -8.117172e-03
## 2016-12-15 3.883228e-03
## 2016-12-16 -1.750623e-03
## 2016-12-19 1.975121e-03
## 2016-12-20 3.637512e-03
## 2016-12-21 -2.457361e-03
## 2016-12-22 -1.862974e-03
## 2016-12-23 1.251715e-03
## 2016-12-27 2.248373e-03
## 2016-12-28 -8.356529e-03
## 2016-12-29 -2.933047e-04
## 2016-12-30 -4.637050e-03
## 2017-01-03 8.486575e-03
## 2017-01-04 5.722274e-03
## 2017-01-05 -7.706705e-04
## 2017-01-06 3.516959e-03
## 2017-01-09 -3.548594e-03
## 2017-01-10 0.000000e+00
## 2017-01-11 2.829638e-03
## 2017-01-12 -2.144809e-03
## 2017-01-13 1.849841e-03
## 2017-01-17 -2.967503e-03
## 2017-01-18 1.763754e-03
## 2017-01-19 -3.609309e-03
## 2017-01-20 3.366238e-03
## 2017-01-23 -2.690125e-03
## 2017-01-24 6.564594e-03
## 2017-01-25 8.026091e-03
## 2017-01-26 -7.353842e-04
## 2017-01-27 -8.664642e-04
## 2017-01-30 -6.009543e-03
## 2017-01-31 -8.899053e-04
## 2017-02-01 2.983636e-04
## 2017-02-02 5.703095e-04
## 2017-02-03 7.264758e-03
## 2017-02-06 -2.115357e-03
## 2017-02-07 2.268290e-04
## 2017-02-08 6.933225e-04
## 2017-02-09 5.752546e-03
## 2017-02-10 3.566050e-03
## 2017-02-13 5.245845e-03
## 2017-02-14 4.007335e-03
## 2017-02-15 4.992309e-03
## 2017-02-16 -8.641179e-04
## 2017-02-17 1.678556e-03
## 2017-02-21 6.048066e-03
## 2017-02-22 -1.082200e-03
## 2017-02-23 4.189870e-04
## 2017-02-24 1.493364e-03
## 2017-02-27 1.017983e-03
## 2017-02-28 -2.578376e-03
## 2017-03-01 1.367385e-02
## 2017-03-02 -5.859880e-03
## 2017-03-03 5.038771e-04
## 2017-03-06 -3.277241e-03
## 2017-03-07 -2.913374e-03
## 2017-03-08 -2.284216e-03
## 2017-03-09 7.998955e-04
## 2017-03-10 3.268670e-03
## 2017-03-13 3.666328e-04
## 2017-03-14 -3.379027e-03
## 2017-03-15 8.374753e-03
## 2017-03-16 -1.626710e-03
## 2017-03-17 -1.314315e-03
## 2017-03-20 -2.009893e-03
## 2017-03-21 -1.240797e-02
## 2017-03-22 1.889886e-03
## 2017-03-23 -1.060270e-03
## 2017-03-24 -8.439961e-04
## 2017-03-27 -1.019587e-03
## 2017-03-28 7.251474e-03
## 2017-03-29 1.085325e-03
## 2017-03-30 2.935110e-03
## 2017-03-31 -2.255048e-03
## 2017-04-03 -1.642126e-03
## 2017-04-04 5.595225e-04
## 2017-04-05 -3.054861e-03
## 2017-04-06 1.929509e-03
## 2017-04-07 -8.271301e-04
## 2017-04-10 6.876865e-04
## 2017-04-11 -1.433879e-03
## 2017-04-12 -3.759951e-03
## 2017-04-13 -6.814694e-03
## 2017-04-17 8.613349e-03
## 2017-04-18 -2.903380e-03
## 2017-04-19 -1.716351e-03
## 2017-04-20 7.557263e-03
## 2017-04-21 -3.035073e-03
## 2017-04-24 1.084007e-02
## 2017-04-25 6.090687e-03
## 2017-04-26 -4.857034e-04
## 2017-04-27 5.529201e-04
## 2017-04-28 -1.913147e-03
## 2017-05-01 1.732291e-03
## 2017-05-02 1.189050e-03
## 2017-05-03 -1.271361e-03
## 2017-05-04 5.821028e-04
## 2017-05-05 4.088695e-03
## 2017-05-08 3.744608e-05
## 2017-05-09 -1.025249e-03
## 2017-05-10 1.130601e-03
## 2017-05-11 -2.162809e-03
## 2017-05-12 -1.478441e-03
## 2017-05-15 4.776514e-03
## 2017-05-16 -6.868968e-04
## 2017-05-17 -1.817821e-02
## 2017-05-18 3.686819e-03
## 2017-05-19 6.767500e-03
## 2017-05-22 5.160132e-03
## 2017-05-23 1.837872e-03
## 2017-05-24 2.489127e-03
## 2017-05-25 4.441948e-03
## 2017-05-26 3.105500e-04
## 2017-05-30 -1.204624e-03
## 2017-05-31 -4.599687e-04
## 2017-06-01 7.571113e-03
## 2017-06-02 3.707731e-03
## 2017-06-05 -1.217665e-03
## 2017-06-06 -2.779040e-03
## 2017-06-07 1.568257e-03
## 2017-06-08 2.672045e-04
## 2017-06-09 -8.299890e-04
## 2017-06-12 -9.787632e-04
## 2017-06-13 4.511505e-03
## 2017-06-14 -9.958309e-04
## 2017-06-15 -2.239598e-03
## 2017-06-16 2.836392e-04
## 2017-06-19 8.347229e-03
## 2017-06-20 -6.696638e-03
## 2017-06-21 -5.826444e-04
## 2017-06-22 -4.557819e-04
## 2017-06-23 1.560916e-03
## 2017-06-26 3.158016e-04
## 2017-06-27 -8.072825e-03
## 2017-06-28 8.808066e-03
## 2017-06-29 -8.600023e-03
## 2017-06-30 1.533232e-03
## 2017-07-03 2.310834e-03
## 2017-07-05 1.453279e-03
## 2017-07-06 -9.368824e-03
## 2017-07-07 6.403126e-03
## 2017-07-10 9.277662e-04
## 2017-07-11 -7.826809e-04
## 2017-07-12 7.305608e-03
## 2017-07-13 1.874584e-03
## 2017-07-14 4.673503e-03
## 2017-07-17 -5.291286e-05
## 2017-07-18 5.978570e-04
## 2017-07-19 5.372639e-03
## 2017-07-20 -1.536593e-04
## 2017-07-21 -3.678716e-04
## 2017-07-24 -1.063735e-03
## 2017-07-25 2.923172e-03
## 2017-07-26 2.826638e-04
## 2017-07-27 -9.726882e-04
## 2017-07-28 -1.341115e-03
## 2017-07-31 -7.281457e-04
## 2017-08-01 2.449115e-03
## 2017-08-02 4.926484e-04
## 2017-08-03 -2.183654e-03
## 2017-08-04 1.889104e-03
## 2017-08-07 1.647200e-03
## 2017-08-08 -2.414433e-03
## 2017-08-09 -3.636085e-04
## 2017-08-10 -1.447444e-02
## 2017-08-11 1.275570e-03
## 2017-08-14 1.004375e-02
## 2017-08-15 -4.988081e-04
## 2017-08-16 1.420103e-03
## 2017-08-17 -1.543695e-02
## 2017-08-18 -1.835367e-03
## 2017-08-21 1.162651e-03
## 2017-08-22 9.940780e-03
## 2017-08-23 -3.453593e-03
## 2017-08-24 -2.074462e-03
## 2017-08-25 1.672869e-03
## 2017-08-28 4.870719e-04
## 2017-08-29 8.428219e-04
## 2017-08-30 4.615149e-03
## 2017-08-31 5.720976e-03
## 2017-09-01 1.982541e-03
## 2017-09-05 -7.550807e-03
## 2017-09-06 3.128727e-03
## 2017-09-07 -1.784360e-04
## 2017-09-08 -1.488851e-03
## 2017-09-11 1.083930e-02
## 2017-09-12 3.363948e-03
## 2017-09-13 7.571208e-04
## 2017-09-14 -1.100718e-03
## 2017-09-15 1.847181e-03
## 2017-09-18 1.455921e-03
## 2017-09-19 1.110195e-03
## 2017-09-20 6.343479e-04
## 2017-09-21 -3.045917e-03
## 2017-09-22 6.477937e-04
## 2017-09-25 -2.222050e-03
## 2017-09-26 7.216682e-05
## 2017-09-27 4.085144e-03
## 2017-09-28 1.204616e-03
## 2017-09-29 3.705110e-03
## 2017-10-02 3.874004e-03
## 2017-10-03 2.158838e-03
## 2017-10-04 1.246720e-03
## 2017-10-05 5.646787e-03
## 2017-10-06 -1.073634e-03
## 2017-10-09 -1.804434e-03
## 2017-10-10 2.322413e-03
## 2017-10-11 1.803507e-03
## 2017-10-12 -1.686753e-03
## 2017-10-13 8.781072e-04
## 2017-10-16 1.750753e-03
## 2017-10-17 6.725787e-04
## 2017-10-18 7.423352e-04
## 2017-10-19 3.279979e-04
## 2017-10-20 5.116843e-03
## 2017-10-23 -3.972484e-03
## 2017-10-24 1.617909e-03
## 2017-10-25 -4.663050e-03
## 2017-10-26 1.270946e-03
## 2017-10-27 8.073022e-03
## 2017-10-30 -3.192470e-03
## 2017-10-31 9.444588e-04
## 2017-11-01 1.592110e-03
## 2017-11-02 1.899661e-04
## 2017-11-03 3.097075e-03
## 2017-11-06 1.271251e-03
## 2017-11-07 -1.891028e-04
## 2017-11-08 1.443655e-03
## 2017-11-09 -3.761888e-03
## 2017-11-10 -8.976437e-04
## 2017-11-13 9.836343e-04
## 2017-11-14 -2.309609e-03
## 2017-11-15 -5.525676e-03
## 2017-11-16 8.196058e-03
## 2017-11-17 -2.625963e-03
## 2017-11-20 1.275683e-03
## 2017-11-21 6.541139e-03
## 2017-11-22 -7.502611e-04
## 2017-11-24 2.056095e-03
## 2017-11-27 -3.842577e-04
## 2017-11-28 9.848513e-03
## 2017-11-29 -3.692258e-04
## 2017-11-30 8.190951e-03
## 2017-12-01 -2.024531e-03
## 2017-12-04 -1.052157e-03
## 2017-12-05 -3.739382e-03
## 2017-12-06 -1.141053e-04
## 2017-12-07 2.932358e-03
## 2017-12-08 5.506306e-03
## 2017-12-11 3.201957e-03
## 2017-12-12 1.548922e-03
## 2017-12-13 -4.729568e-04
## 2017-12-14 -4.070859e-03
## 2017-12-15 8.974344e-03
## 2017-12-18 5.362807e-03
## 2017-12-19 -3.230269e-03
## 2017-12-20 -8.278933e-04
## 2017-12-21 1.985656e-03
## 2017-12-22 -4.581665e-04
## 2017-12-26 -1.058415e-03
## 2017-12-27 7.909409e-04
## 2017-12-28 1.833999e-03
## 2017-12-29 -5.183153e-03
## 2018-01-02 8.303362e-03
## 2018-01-03 6.398819e-03
## 2018-01-04 4.028636e-03
## 2018-01-05 7.033767e-03
## 2018-01-08 1.662344e-03
## 2018-01-09 1.302932e-03
## 2018-01-10 -1.112227e-03
## 2018-01-11 7.033647e-03
## 2018-01-12 6.749603e-03
## 2018-01-16 -3.524487e-03
## 2018-01-17 9.415052e-03
## 2018-01-18 -1.616390e-03
## 2018-01-19 4.385235e-03
## 2018-01-22 8.066727e-03
## 2018-01-23 2.174365e-03
## 2018-01-24 -5.599758e-04
## 2018-01-25 6.026209e-04
## 2018-01-26 1.184120e-02
## 2018-01-29 -6.731974e-03
## 2018-01-30 -1.089882e-02
## 2018-01-31 4.889854e-04
## 2018-02-01 -6.480886e-04
## 2018-02-02 -2.120855e-02
## 2018-02-05 -4.097923e-02
## 2018-02-06 1.744092e-02
## 2018-02-07 -5.001589e-03
## 2018-02-08 -3.753642e-02
## 2018-02-09 1.493609e-02
## 2018-02-12 1.391458e-02
## 2018-02-13 2.612930e-03
## 2018-02-14 1.340246e-02
## 2018-02-15 1.206911e-02
## 2018-02-16 3.734695e-04
## 2018-02-20 -5.841389e-03
## 2018-02-21 -5.496503e-03
## 2018-02-22 9.735511e-04
## 2018-02-23 1.602838e-02
## 2018-02-26 1.175702e-02
## 2018-02-27 -1.270689e-02
## 2018-02-28 -1.109579e-02
## 2018-03-01 -1.332440e-02
## 2018-03-02 5.071603e-03
## 2018-03-05 1.103203e-02
## 2018-03-06 2.638859e-03
## 2018-03-07 -4.838746e-04
## 2018-03-08 4.463078e-03
## 2018-03-09 1.737883e-02
## 2018-03-12 -1.273985e-03
## 2018-03-13 -6.363577e-03
## 2018-03-14 -5.724522e-03
## 2018-03-15 -7.819304e-04
## 2018-03-16 1.703447e-03
## 2018-03-19 -1.420420e-02
## 2018-03-20 1.481805e-03
## 2018-03-21 -1.843990e-03
## 2018-03-22 -2.516289e-02
## 2018-03-23 -2.096688e-02
## 2018-03-26 2.715726e-02
## 2018-03-27 -1.727631e-02
## 2018-03-28 -2.916657e-03
## 2018-03-29 1.376972e-02
## 2018-04-02 -2.233742e-02
## 2018-04-03 1.261487e-02
## 2018-04-04 1.156648e-02
## 2018-04-05 6.862864e-03
## 2018-04-06 -2.192025e-02
## 2018-04-09 3.336549e-03
## 2018-04-10 1.672695e-02
## 2018-04-11 -5.525365e-03
## 2018-04-12 8.250750e-03
## 2018-04-13 -2.886625e-03
## 2018-04-16 8.109038e-03
## 2018-04-17 1.066150e-02
## 2018-04-18 8.313658e-04
## 2018-04-19 -5.726125e-03
## 2018-04-20 -8.536532e-03
## 2018-04-23 5.623151e-05
## 2018-04-24 -1.338056e-02
## 2018-04-25 1.837059e-03
## 2018-04-26 1.043420e-02
## 2018-04-27 1.113625e-03
## 2018-04-30 -8.187491e-03
## 2018-05-01 2.549045e-03
## 2018-05-02 -7.205864e-03
## 2018-05-03 -2.253674e-03
## 2018-05-04 1.281118e-02
## 2018-05-07 3.457946e-03
## 2018-05-08 -2.656413e-04
## 2018-05-09 9.682220e-03
## 2018-05-10 9.370644e-03
## 2018-05-11 1.707596e-03
## 2018-05-14 8.834895e-04
## 2018-05-15 -6.842140e-03
## 2018-05-16 4.060562e-03
## 2018-05-17 -8.558723e-04
## 2018-05-18 -2.632195e-03
## 2018-05-21 7.386753e-03
## 2018-05-22 -3.135762e-03
## 2018-05-23 3.248410e-03
## 2018-05-24 -2.023213e-03
## 2018-05-25 -2.357221e-03
## 2018-05-29 -1.156419e-02
## 2018-05-30 1.269579e-02
## 2018-05-31 -6.879560e-03
## 2018-06-01 1.084923e-02
## 2018-06-04 4.479598e-03
## 2018-06-05 7.025931e-04
## 2018-06-06 8.567393e-03
## 2018-06-07 -7.141887e-04
## 2018-06-08 3.125904e-03
## 2018-06-11 1.068708e-03
## 2018-06-12 1.743385e-03
## 2018-06-13 -4.026128e-03
## 2018-06-14 2.471550e-03
## 2018-06-15 -1.017103e-03
## 2018-06-18 -2.126128e-03
## 2018-06-19 -4.023402e-03
## 2018-06-20 1.712154e-03
## 2018-06-21 -6.345510e-03
## 2018-06-22 1.861934e-03
## 2018-06-25 -1.372467e-02
## 2018-06-26 2.204577e-03
## 2018-06-27 -8.604355e-03
## 2018-06-28 6.178690e-03
## 2018-06-29 7.584031e-04
## 2018-07-02 3.067958e-03
## 2018-07-03 -4.947351e-03
## 2018-07-05 8.620803e-03
## 2018-07-06 8.481282e-03
## 2018-07-09 8.822986e-03
## 2018-07-10 3.473267e-03
## 2018-07-11 -7.094203e-03
## 2018-07-12 8.749042e-03
## 2018-07-13 1.079238e-03
## 2018-07-16 -1.028136e-03
## 2018-07-17 3.973699e-03
## 2018-07-18 2.160512e-03
## 2018-07-19 -3.952993e-03
## 2018-07-20 -9.484477e-04
## 2018-07-23 1.838049e-03
## 2018-07-24 4.780911e-03
## 2018-07-25 9.101605e-03
## 2018-07-26 -3.032296e-03
## 2018-07-27 -6.562209e-03
## 2018-07-30 -5.754170e-03
## 2018-07-31 4.884729e-03
## 2018-08-01 -1.040352e-03
## 2018-08-02 4.926445e-03
## 2018-08-03 4.644183e-03
## 2018-08-06 3.538227e-03
## 2018-08-07 2.824182e-03
## 2018-08-08 -2.623800e-04
## 2018-08-09 -1.441674e-03
## 2018-08-10 -7.113888e-03
## 2018-08-13 -4.005992e-03
## 2018-08-14 6.389255e-03
## 2018-08-15 -7.602165e-03
## 2018-08-16 7.919408e-03
## 2018-08-17 3.323116e-03
## 2018-08-20 2.428018e-03
## 2018-08-21 2.068536e-03
## 2018-08-22 -3.981519e-04
## 2018-08-23 -1.691262e-03
## 2018-08-24 6.198840e-03
## 2018-08-27 7.670409e-03
## 2018-08-28 2.692786e-04
## 2018-08-29 5.701434e-03
## 2018-08-30 -4.430329e-03
## 2018-08-31 1.344776e-04
## 2018-09-04 -1.654322e-03
## 2018-09-05 -2.803127e-03
## 2018-09-06 -3.652305e-03
## 2018-09-07 -2.213345e-03
## 2018-09-10 1.897827e-03
## 2018-09-11 3.739842e-03
## 2018-09-12 3.566718e-04
## 2018-09-13 5.282254e-03
## 2018-09-14 2.754816e-04
## 2018-09-17 -5.569722e-03
## 2018-09-18 5.369015e-03
## 2018-09-19 1.253273e-03
## 2018-09-20 7.840592e-03
## 2018-09-21 -3.685330e-04
## 2018-09-24 -3.515688e-03
## 2018-09-25 -1.305096e-03
## 2018-09-26 -3.289278e-03
## 2018-09-27 2.763287e-03
## 2018-09-28 -6.870281e-06
## 2018-10-01 3.641105e-03
## 2018-10-02 -3.966901e-04
## 2018-10-03 7.115197e-04
## 2018-10-04 -8.169483e-03
## 2018-10-05 -5.527979e-03
## 2018-10-08 -3.951164e-04
## 2018-10-09 -1.417904e-03
## 2018-10-10 -3.286423e-02
## 2018-10-11 -2.057301e-02
## 2018-10-12 1.420620e-02
## 2018-10-15 -5.904979e-03
## 2018-10-16 2.149560e-02
## 2018-10-17 -2.526624e-04
## 2018-10-18 -1.439192e-02
## 2018-10-19 -3.611699e-04
## 2018-10-22 -4.299527e-03
## 2018-10-23 -5.511830e-03
## 2018-10-24 -3.086443e-02
## 2018-10-25 1.862504e-02
## 2018-10-26 -1.732726e-02
## 2018-10-29 -6.559599e-03
## 2018-10-30 1.566678e-02
## 2018-10-31 1.085133e-02
## 2018-11-01 1.055784e-02
## 2018-11-02 -6.316686e-03
## 2018-11-05 5.600317e-03
## 2018-11-06 6.259296e-03
## 2018-11-07 2.120886e-02
## 2018-11-08 -2.508917e-03
## 2018-11-09 -9.199014e-03
## 2018-11-12 -1.970149e-02
## 2018-11-13 -1.481920e-03
## 2018-11-14 -7.567411e-03
## 2018-11-15 1.059375e-02
## 2018-11-16 2.223306e-03
## 2018-11-19 -1.664311e-02
## 2018-11-20 -1.815124e-02
## 2018-11-21 3.043291e-03
## 2018-11-23 -6.554842e-03
## 2018-11-26 1.553237e-02
## 2018-11-27 3.261692e-03
## 2018-11-28 2.297398e-02
## 2018-11-29 -2.183108e-03
## 2018-11-30 8.170748e-03
## 2018-12-03 1.094143e-02
## 2018-12-04 -3.236490e-02
## 2018-12-06 -1.522228e-03
## 2018-12-07 -2.332012e-02
## 2018-12-10 1.762154e-03
## 2018-12-11 -3.563464e-04
## 2018-12-12 5.419504e-03
## 2018-12-13 -1.999302e-04
## 2018-12-14 -1.908671e-02
## 2018-12-17 -2.077348e-02
## 2018-12-18 8.640070e-05
## 2018-12-19 -1.539571e-02
## 2018-12-20 -1.577211e-02
## 2018-12-21 -2.058823e-02
## 2018-12-24 -2.711225e-02
## 2018-12-26 4.959374e-02
## 2018-12-27 8.562681e-03
## 2018-12-28 -1.241583e-03
## 2018-12-31 8.492484e-03
## 2019-01-02 1.268497e-03
## 2019-01-03 -2.475673e-02
## 2019-01-04 3.433571e-02
## 2019-01-07 7.010435e-03
## 2019-01-08 9.695285e-03
## 2019-01-09 4.098046e-03
## 2019-01-10 4.518419e-03
## 2019-01-11 -1.462979e-04
## 2019-01-14 -5.257525e-03
## 2019-01-15 1.072169e-02
## 2019-01-16 2.221986e-03
## 2019-01-17 7.591400e-03
## 2019-01-18 1.318305e-02
## 2019-01-22 -1.415731e-02
## 2019-01-23 2.202913e-03
## 2019-01-24 1.375726e-03
## 2019-01-25 8.488694e-03
## 2019-01-28 -7.846827e-03
## 2019-01-29 -1.456247e-03
## 2019-01-30 1.554926e-02
## 2019-01-31 8.597396e-03
## 2019-02-01 8.986099e-04
## 2019-02-04 6.776237e-03
## 2019-02-05 4.708420e-03
## 2019-02-06 -2.224438e-03
## 2019-02-07 -9.357140e-03
## 2019-02-08 6.762011e-04
## 2019-02-11 7.091031e-04
## 2019-02-12 1.289022e-02
## 2019-02-13 3.023995e-03
## 2019-02-14 -2.651642e-03
## 2019-02-15 1.087875e-02
## 2019-02-19 1.498743e-03
## 2019-02-20 1.777111e-03
## 2019-02-21 -3.526437e-03
## 2019-02-22 6.411102e-03
## 2019-02-25 1.231862e-03
## 2019-02-26 -7.904571e-04
## 2019-02-27 -5.440492e-04
## 2019-02-28 -2.825508e-03
## 2019-03-01 6.895321e-03
## 2019-03-04 -3.880558e-03
## 2019-03-05 -1.131533e-03
## 2019-03-06 -6.524099e-03
## 2019-03-07 -8.125717e-03
## 2019-03-08 -2.131689e-03
## 2019-03-11 1.466604e-02
## 2019-03-12 2.953318e-03
## 2019-03-13 6.949584e-03
## 2019-03-14 -8.680226e-04
## 2019-03-15 4.984903e-03
## 2019-03-18 3.705947e-03
## 2019-03-19 -1.305615e-04
## 2019-03-20 -2.944354e-03
## 2019-03-21 1.085248e-02
## 2019-03-22 -1.897450e-02
## 2019-03-25 -8.390208e-04
## 2019-03-26 7.182726e-03
## 2019-03-27 -4.644325e-03
## 2019-03-28 3.589481e-03
## 2019-03-29 6.734280e-03
## 2019-04-01 1.156860e-02
## 2019-04-02 1.745577e-05
## 2019-04-03 2.148377e-03
## 2019-04-04 2.084635e-03
## 2019-04-05 4.636433e-03
## 2019-04-08 1.047460e-03
## 2019-04-09 -6.067495e-03
## 2019-04-10 3.477872e-03
## 2019-04-11 3.812292e-05
## 2019-04-12 6.609324e-03
## 2019-04-15 -6.293691e-04
## 2019-04-16 5.093582e-04
## 2019-04-17 -2.273812e-03
## 2019-04-18 1.579092e-03
## 2019-04-22 1.012018e-03
## 2019-04-23 8.841206e-03
## 2019-04-24 -2.191763e-03
## 2019-04-25 -3.689736e-04
## 2019-04-26 4.685292e-03
## 2019-04-29 1.071522e-03
## 2019-04-30 9.514171e-04
## 2019-05-01 -7.502163e-03
## 2019-05-02 -2.123985e-03
## 2019-05-03 9.638279e-03
## 2019-05-06 -4.470988e-03
## 2019-05-07 -1.651165e-02
## 2019-05-08 -1.605425e-03
## 2019-05-09 -3.021425e-03
## 2019-05-10 3.720297e-03
## 2019-05-13 -2.413056e-02
## 2019-05-14 8.015945e-03
## 2019-05-15 5.838975e-03
## 2019-05-16 8.895287e-03
## 2019-05-17 -5.837333e-03
## 2019-05-20 -6.749378e-03
## 2019-05-21 8.495836e-03
## 2019-05-22 -2.824396e-03
## 2019-05-23 -1.191415e-02
## 2019-05-24 1.353559e-03
## 2019-05-28 -8.375677e-03
## 2019-05-29 -6.911912e-03
## 2019-05-30 2.098471e-03
## 2019-05-31 -1.319537e-02
## 2019-06-03 -2.765241e-03
## 2019-06-04 2.143237e-02
## 2019-06-05 8.161854e-03
## 2019-06-06 6.135587e-03
## 2019-06-07 1.049770e-02
## 2019-06-10 4.660044e-03
## 2019-06-11 -3.498800e-04
## 2019-06-12 -2.037579e-03
## 2019-06-13 4.097382e-03
## 2019-06-14 -1.611512e-03
## 2019-06-17 9.317494e-04
## 2019-06-18 9.717400e-03
## 2019-06-19 2.985164e-03
## 2019-06-20 9.472185e-03
## 2019-06-21 -1.259223e-03
## 2019-06-24 -1.731887e-03
## 2019-06-25 -9.496397e-03
## 2019-06-26 -1.233934e-03
## 2019-06-27 3.823176e-03
## 2019-06-28 5.757453e-03
## 2019-07-01 7.672301e-03
## 2019-07-02 2.928126e-03
## 2019-07-03 7.672378e-03
## 2019-07-05 -1.805902e-03
## 2019-07-08 -4.835444e-03
## 2019-07-09 1.236557e-03
## 2019-07-10 4.510689e-03
## 2019-07-11 2.285227e-03
## 2019-07-12 4.620175e-03
## 2019-07-15 1.758691e-04
## 2019-07-16 -3.403779e-03
## 2019-07-17 -6.531244e-03
## 2019-07-18 3.581998e-03
## 2019-07-19 -6.176735e-03
## 2019-07-22 2.828695e-03
## 2019-07-23 6.847483e-03
## 2019-07-24 4.688148e-03
## 2019-07-25 -5.262401e-03
## 2019-07-26 7.387691e-03
## 2019-07-29 -1.616114e-03
## 2019-07-30 -2.578655e-03
## 2019-07-31 -1.088553e-02
## 2019-08-01 -8.998794e-03
## 2019-08-02 -7.282740e-03
## 2019-08-05 -2.977782e-02
## 2019-08-06 1.301702e-02
## 2019-08-07 7.668759e-04
## 2019-08-08 1.876230e-02
## 2019-08-09 -6.616607e-03
## 2019-08-12 -1.231732e-02
## 2019-08-13 1.513169e-02
## 2019-08-14 -2.929275e-02
## 2019-08-15 2.464268e-03
## 2019-08-16 1.442612e-02
## 2019-08-19 1.210587e-02
## 2019-08-20 -7.914727e-03
## 2019-08-21 8.246799e-03
## 2019-08-22 -5.060750e-04
## 2019-08-23 -2.594634e-02
## 2019-08-26 1.098299e-02
## 2019-08-27 -3.203181e-03
## 2019-08-28 6.545480e-03
## 2019-08-29 1.268729e-02
## 2019-08-30 6.427873e-04
## 2019-09-03 -6.899100e-03
## 2019-09-04 1.084208e-02
## 2019-09-05 1.300981e-02
## 2019-09-06 9.106052e-04
## 2019-09-09 -9.401016e-05
## 2019-09-10 3.223044e-04
## 2019-09-11 7.229681e-03
## 2019-09-12 2.879153e-03
## 2019-09-13 -7.244141e-04
## 2019-09-16 -3.135587e-03
## 2019-09-17 2.581752e-03
## 2019-09-18 3.426919e-04
## 2019-09-19 1.997486e-05
## 2019-09-20 -4.895577e-03
## 2019-09-23 -9.693590e-05
## 2019-09-24 -8.416371e-03
## 2019-09-25 6.158572e-03
## 2019-09-26 -2.428916e-03
## 2019-09-27 -5.316352e-03
## 2019-09-30 5.047607e-03
## 2019-10-01 -1.225837e-02
## 2019-10-02 -1.790320e-02
## 2019-10-03 7.971913e-03
## 2019-10-04 1.421690e-02
## 2019-10-07 -4.478295e-03
## 2019-10-08 -1.556082e-02
## 2019-10-09 9.104492e-03
## 2019-10-10 6.415696e-03
## 2019-10-11 1.093898e-02
## 2019-10-14 -1.387119e-03
## 2019-10-15 9.955677e-03
## 2019-10-16 -1.999543e-03
## 2019-10-17 2.762832e-03
## 2019-10-18 -3.919345e-03
## 2019-10-21 6.871616e-03
## 2019-10-22 -3.568667e-03
## 2019-10-23 2.847149e-03
## 2019-10-24 1.920446e-03
## 2019-10-25 4.072701e-03
## 2019-10-28 5.581338e-03
## 2019-10-29 -8.324052e-04
## 2019-10-30 3.253370e-03
## 2019-10-31 -3.022861e-03
## 2019-11-01 9.662312e-03
## 2019-11-04 3.704089e-03
## 2019-11-05 -1.185699e-03
## 2019-11-06 7.024972e-04
## 2019-11-07 2.730095e-03
## 2019-11-08 2.560676e-03
## 2019-11-11 -1.962467e-03
## 2019-11-12 1.564646e-03
## 2019-11-13 7.115345e-04
## 2019-11-14 8.370428e-04
## 2019-11-15 7.695488e-03
## 2019-11-18 5.031527e-04
## 2019-11-19 -5.925942e-04
## 2019-11-20 -3.756184e-03
## 2019-11-21 -1.582752e-03
## 2019-11-22 2.174936e-03
## 2019-11-25 7.507292e-03
## 2019-11-26 2.195570e-03
## 2019-11-27 4.174424e-03
## 2019-11-29 -4.011220e-03
## 2019-12-02 -8.631021e-03
## 2019-12-03 -6.638095e-03
## 2019-12-04 6.323568e-03
## 2019-12-05 1.500251e-03
## 2019-12-06 9.135724e-03
## 2019-12-09 -3.162821e-03
## 2019-12-10 -1.096934e-03
## 2019-12-11 2.908158e-03
## 2019-12-12 8.575226e-03
## 2019-12-13 7.258195e-05
## 2019-12-16 7.147785e-03
## 2019-12-17 3.352924e-04
## 2019-12-18 -4.323002e-04
## 2019-12-19 4.459292e-03
## 2019-12-20 4.944781e-03
## 2019-12-23 8.661436e-04
## 2019-12-24 -1.954482e-04
## 2019-12-26 5.128167e-03
## 2019-12-27 3.398490e-05
## 2019-12-30 -5.780823e-03
## 2019-12-31 2.946022e-03
## 2020-01-02 8.378803e-03
## 2020-01-03 -7.059871e-03
## 2020-01-06 3.533373e-03
## 2020-01-07 -2.803238e-03
## 2020-01-08 4.902451e-03
## 2020-01-09 6.655262e-03
## 2020-01-10 -2.855179e-03
## 2020-01-13 6.976215e-03
## 2020-01-14 -1.514533e-03
## 2020-01-15 1.870197e-03
## 2020-01-16 8.366553e-03
## 2020-01-17 3.862162e-03
## 2020-01-21 -2.651978e-03
## 2020-01-22 2.890761e-04
## 2020-01-23 1.140977e-03
## 2020-01-24 -9.042161e-03
## 2020-01-27 -1.573071e-02
## 2020-01-28 1.005358e-02
## 2020-01-29 -8.668742e-04
## 2020-01-30 3.134359e-03
## 2020-01-31 -1.770582e-02
## 2020-02-03 7.254614e-03
## 2020-02-04 1.498041e-02
## 2020-02-05 1.125060e-02
## 2020-02-06 3.325673e-03
## 2020-02-07 -5.400854e-03
## 2020-02-10 7.326398e-03
## 2020-02-11 1.688473e-03
## 2020-02-12 6.462646e-03
## 2020-02-13 -1.630446e-03
## 2020-02-14 1.843533e-03
## 2020-02-18 -2.919943e-03
## 2020-02-19 4.705786e-03
## 2020-02-20 -3.815520e-03
## 2020-02-21 -1.051810e-02
## 2020-02-24 -3.351363e-02
## 2020-02-25 -3.028000e-02
## 2020-02-26 -3.778540e-03
## 2020-02-27 -4.416324e-02
## 2020-02-28 -8.238340e-03
## 2020-03-02 4.603923e-02
## 2020-03-03 -2.810790e-02
## 2020-03-04 4.220259e-02
## 2020-03-05 -3.392208e-02
## 2020-03-06 -1.705385e-02
## 2020-03-09 -7.596970e-02
## 2020-03-10 4.939631e-02
## 2020-03-11 -4.886844e-02
## 2020-03-12 -9.511268e-02
## 2020-03-13 9.287125e-02
## 2020-03-16 -1.198406e-01
## 2020-03-17 5.995485e-02
## 2020-03-18 -5.183076e-02
## 2020-03-19 4.707808e-03
## 2020-03-20 -4.335951e-02
## 2020-03-23 -2.929387e-02
## 2020-03-24 9.382774e-02
## 2020-03-25 1.153501e-02
## 2020-03-26 6.241416e-02
## 2020-03-27 -3.368735e-02
## 2020-03-30 3.351601e-02
## 2020-03-31 -1.601272e-02
## 2020-04-01 -4.414243e-02
## 2020-04-02 2.282935e-02
## 2020-04-03 -1.513713e-02
## 2020-04-06 7.033132e-02
## 2020-04-07 -1.603053e-03
## 2020-04-08 3.405645e-02
## 2020-04-09 1.448741e-02
## 2020-04-13 -1.010466e-02
## 2020-04-14 3.057259e-02
## 2020-04-15 -2.203044e-02
## 2020-04-16 5.816690e-03
## 2020-04-17 2.679359e-02
## 2020-04-20 -1.788105e-02
## 2020-04-21 -3.067480e-02
## 2020-04-22 2.293025e-02
## 2020-04-23 -5.394222e-04
## 2020-04-24 1.391806e-02
## 2020-04-27 1.471407e-02
## 2020-04-28 -5.242380e-03
## 2020-04-29 2.658392e-02
## 2020-04-30 -9.212446e-03
## 2020-05-01 -2.805903e-02
## 2020-05-04 4.249827e-03
## 2020-05-05 9.040556e-03
## 2020-05-06 -6.979410e-03
## 2020-05-07 1.150463e-02
## 2020-05-08 1.687154e-02
## 2020-05-11 1.330780e-04
## 2020-05-12 -2.050032e-02
## 2020-05-13 -1.746272e-02
## 2020-05-14 1.152482e-02
## 2020-05-15 3.926363e-03
## 2020-05-18 3.150119e-02
## 2020-05-19 -1.048440e-02
## 2020-05-20 1.665110e-02
## 2020-05-21 -7.773596e-03
## 2020-05-22 2.353711e-03
## 2020-05-26 1.228918e-02
## 2020-05-27 1.482730e-02
## 2020-05-28 -2.107915e-03
## 2020-05-29 4.812336e-03
## 2020-06-01 3.751235e-03
## 2020-06-02 8.210833e-03
## 2020-06-03 1.364898e-02
## 2020-06-04 -3.368702e-03
## 2020-06-05 2.621165e-02
## 2020-06-08 1.204158e-02
## 2020-06-09 -7.799171e-03
## 2020-06-10 -5.313091e-03
## 2020-06-11 -5.894406e-02
## 2020-06-12 1.306084e-02
## 2020-06-15 8.312217e-03
## 2020-06-16 1.896240e-02
## 2020-06-17 -3.600300e-03
## 2020-06-18 5.942200e-04
## 2020-06-19 -5.649495e-03
## 2020-06-22 6.495095e-03
## 2020-06-23 4.307420e-03
## 2020-06-24 -2.585515e-02
## 2020-06-25 1.095945e-02
## 2020-06-26 -2.422691e-02
## 2020-06-29 1.468568e-02
## 2020-06-30 1.540988e-02
## 2020-07-01 5.022133e-03
## 2020-07-02 4.541251e-03
## 2020-07-06 1.588173e-02
## 2020-07-07 -1.081853e-02
## 2020-07-08 7.827462e-03
## 2020-07-09 -5.643606e-03
## 2020-07-10 1.046620e-02
## 2020-07-13 -9.362541e-03
## 2020-07-14 1.340637e-02
## 2020-07-15 9.082051e-03
## 2020-07-16 -3.406101e-03
## 2020-07-17 2.848612e-03
## 2020-07-20 8.406939e-03
## 2020-07-21 1.679037e-03
## 2020-07-22 5.747082e-03
## 2020-07-23 -1.231986e-02
## 2020-07-24 -6.190400e-03
## 2020-07-27 7.395139e-03
## 2020-07-28 -6.473392e-03
## 2020-07-29 1.242838e-02
## 2020-07-30 -3.750252e-03
## 2020-07-31 7.670505e-03
## 2020-08-03 7.181023e-03
## 2020-08-04 3.611931e-03
## 2020-08-05 6.429743e-03
## 2020-08-06 6.427695e-03
## 2020-08-07 6.330295e-04
## 2020-08-10 2.742218e-03
## 2020-08-11 -7.969132e-03
## 2020-08-12 1.399655e-02
## 2020-08-13 -2.047174e-03
## 2020-08-14 -1.718826e-04
## 2020-08-17 2.709842e-03
## 2020-08-18 2.303389e-03
## 2020-08-19 -4.404395e-03
## 2020-08-20 3.158633e-03
## 2020-08-21 3.441107e-03
## 2020-08-24 1.004372e-02
## 2020-08-25 3.596351e-03
## 2020-08-26 1.019563e-02
## 2020-08-27 1.673044e-03
## 2020-08-28 6.732565e-03
## 2020-08-31 -2.194963e-03
## 2020-09-01 7.525003e-03
## 2020-09-02 1.536591e-02
## 2020-09-03 -3.512584e-02
## 2020-09-04 -8.133027e-03
## 2020-09-08 -2.775634e-02
## 2020-09-09 2.014499e-02
## 2020-09-10 -1.758480e-02
## 2020-09-11 5.330724e-04
## 2020-09-14 1.274183e-02
## 2020-09-15 5.219360e-03
## 2020-09-16 -4.618947e-03
## 2020-09-17 -8.412366e-03
## 2020-09-18 -1.118258e-02
## 2020-09-21 -1.157110e-02
## 2020-09-22 1.051794e-02
## 2020-09-23 -2.372145e-02
## 2020-09-24 2.987459e-03
## 2020-09-25 1.597672e-02
## 2020-09-28 1.611059e-02
## 2020-09-29 -4.812665e-03
## 2020-09-30 8.253718e-03
## 2020-10-01 5.292908e-03
## 2020-10-02 -9.577652e-03
## 2020-10-05 1.797271e-02
## 2020-10-06 -1.397352e-02
## 2020-10-07 1.739675e-02
## 2020-10-08 8.010124e-03
## 2020-10-09 8.793533e-03
## 2020-10-12 1.641581e-02
## 2020-10-13 -6.306919e-03
## 2020-10-14 -6.623142e-03
## 2020-10-15 -1.527755e-03
## 2020-10-16 1.349196e-04
## 2020-10-19 -1.632986e-02
## 2020-10-20 4.727334e-03
## 2020-10-21 -2.195700e-03
## 2020-10-22 5.218925e-03
## 2020-10-23 3.445762e-03
## 2020-10-26 -1.858952e-02
## 2020-10-27 -3.025619e-03
## 2020-10-28 -3.528788e-02
## 2020-10-29 1.194733e-02
## 2020-10-30 -1.212955e-02
## 2020-11-02 1.231820e-02
## 2020-11-03 1.779929e-02
## 2020-11-04 2.204705e-02
## 2020-11-05 1.946019e-02
## 2020-11-06 -2.877153e-04
## 2020-11-09 1.169989e-02
## 2020-11-10 -1.399795e-03
## 2020-11-11 7.651855e-03
## 2020-11-12 -9.978532e-03
## 2020-11-13 1.361034e-02
## 2020-11-16 1.164805e-02
## 2020-11-17 -4.791926e-03
## 2020-11-18 -1.156383e-02
## 2020-11-19 3.946442e-03
## 2020-11-20 -6.792563e-03
## 2020-11-23 5.635931e-03
## 2020-11-24 1.616167e-02
## 2020-11-25 -1.584418e-03
## 2020-11-27 2.396979e-03
## 2020-11-30 -4.595549e-03
## 2020-12-01 1.127119e-02
## 2020-12-02 1.791167e-03
## 2020-12-03 -6.241572e-04
## 2020-12-04 8.836275e-03
## 2020-12-07 -1.935638e-03
## 2020-12-08 2.787148e-03
## 2020-12-09 -7.949202e-03
## 2020-12-10 -1.285108e-03
## 2020-12-11 -1.264997e-03
## 2020-12-14 -4.359259e-03
## 2020-12-15 1.292125e-02
## 2020-12-16 1.772795e-03
## 2020-12-17 5.757655e-03
## 2020-12-18 -3.511118e-03
## 2020-12-21 -3.906279e-03
## 2020-12-22 -2.073093e-03
## 2020-12-23 7.458113e-04
## 2020-12-24 3.536589e-03
## 2020-12-28 8.722529e-03
## 2020-12-29 -2.227380e-03
## 2020-12-30 1.341547e-03
## 2020-12-31 6.438845e-03
## 2021-01-04 -1.475483e-02
## 2021-01-05 7.082595e-03
## 2021-01-06 5.709843e-03
## 2021-01-07 1.484740e-02
## 2021-01-08 5.491863e-03
## 2021-01-11 -6.554751e-03
## 2021-01-12 4.157885e-04
## 2021-01-13 2.275642e-03
## 2021-01-14 -3.753451e-03
## 2021-01-15 -7.190028e-03
## 2021-01-19 8.136379e-03
## 2021-01-20 1.393563e-02
## 2021-01-21 3.167231e-04
## 2021-01-22 -3.010611e-03
## 2021-01-25 3.615839e-03
## 2021-01-26 -1.488834e-03
## 2021-01-27 -2.567788e-02
## 2021-01-28 9.760626e-03
## 2021-01-29 -1.931148e-02
## 2021-02-01 1.605177e-02
## 2021-02-02 1.389822e-02
## 2021-02-03 1.008769e-03
## 2021-02-04 1.085332e-02
## 2021-02-05 3.897495e-03
## 2021-02-08 7.399348e-03
## 2021-02-09 -1.113525e-03
## 2021-02-10 -3.451848e-04
## 2021-02-11 1.662455e-03
## 2021-02-12 4.711033e-03
## 2021-02-16 -5.692724e-04
## 2021-02-17 -3.204021e-04
## 2021-02-18 -4.415836e-03
## 2021-02-19 -1.854897e-03
## 2021-02-22 -7.732839e-03
## 2021-02-23 1.256318e-03
## 2021-02-24 1.135161e-02
## 2021-02-25 -2.447881e-02
## 2021-02-26 -4.750214e-03
## 2021-03-01 2.379076e-02
## 2021-03-02 -8.080852e-03
## 2021-03-03 -1.306622e-02
## 2021-03-04 -1.341721e-02
## 2021-03-05 1.949597e-02
## 2021-03-08 -5.359231e-03
## 2021-03-09 1.415464e-02
## 2021-03-10 6.030314e-03
## 2021-03-11 1.039549e-02
## 2021-03-12 1.015398e-03
## 2021-03-15 6.491921e-03
## 2021-03-16 -1.569684e-03
## 2021-03-17 2.879382e-03
## 2021-03-18 -1.476054e-02
## 2021-03-19 -6.027039e-04
## 2021-03-22 7.025118e-03
## 2021-03-23 -7.630854e-03
## 2021-03-24 -5.467336e-03
## 2021-03-25 5.240266e-03
## 2021-03-26 1.663120e-02
## 2021-03-29 -8.680126e-04
## 2021-03-30 -3.157833e-03
## 2021-03-31 3.622499e-03
## 2021-04-01 1.182520e-02
## 2021-04-05 1.443823e-02
## 2021-04-06 -9.735308e-04
## 2021-04-07 1.475233e-03
## 2021-04-08 4.220633e-03
## 2021-04-09 7.719934e-03
## 2021-04-12 -1.960790e-04
## 2021-04-13 3.294487e-03
## 2021-04-14 -4.087727e-03
## 2021-04-15 1.109419e-02
## 2021-04-16 3.608820e-03
## 2021-04-19 -5.306560e-03
## 2021-04-20 -6.802320e-03
## 2021-04-21 9.306056e-03
## 2021-04-22 -9.210658e-03
## 2021-04-23 1.092870e-02
## 2021-04-26 1.782271e-03
## 2021-04-27 -2.148958e-04
## 2021-04-28 -8.455399e-04
## 2021-04-29 6.762807e-03
SP500 <- SP500[-1,] # remove the first row
names(SP500) <- "SP500"
Betas <- sapply(colnames(Return), function(x) lm(Return[,x]~1+SP500)$coef[2]) #First regression
MktExposure <- lm(colMeans(Return)~1+Betas)$coef[2] #Second regression
### Construct Portfolio
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Return))
# Add a factor exposure constraint: the factor exposure constraint allows the user to set upper and lower bounds on exposures to risk factors. The exposures can be passed in as a vector or matrix. Here we specify a vector for B with arbitrary values, e.g. betas of the assets, with a market risk exposure range from "lower" to "upper" of the estimated value
init.portf <- add.constraint(portfolio=init.portf,
type="factor_exposure",
B = scale(Betas),
lower=MktExposure*0.2,
upper=MktExposure*0.8)
# Add risk and return objective(we need them to calculate the Sharpe ratio)
init.portf <- add.objective(portfolio=init.portf, type="return", name = "mean")
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "StdDev")
### Solve Portfolio: Maximize Sharpe Ratio
# The default action if “mean” and “StdDev” are specified as objectives with optimize_method="ROI" is to maximize quadratic utility. If we want to maximize Sharpe Ratio, we need to pass in maxSR=TRUE to optimize.portfolio
library(ROI)
opt.MaxSR <- optimize.portfolio(R=Return,
portfolio=init.portf,
optimize_method="ROI",
maxSR=TRUE,
trace=TRUE)
# Warning: Inf or -Inf values detected in box constraints, maximum return objectives must have finite box constraint values.
summary(opt.MaxSR) # The optimization summary should be read carefully since not every constraint is guaranteed to be satisfied
## **************************************************
## PortfolioAnalytics Optimization Summary
## **************************************************
##
## Call:
## optimize.portfolio(R = Return, portfolio = init.portf, optimize_method = "ROI",
## trace = TRUE, maxSR = TRUE)
##
## Optimal Weights:
## IBM GE F MSFT
## 0.4256 -0.0625 0.1191 0.5178
##
## Objective Measures:
## StdDev
## 0.01446
##
##
## mean
## 0.0007866
##
##
## Portfolio Assets and Initial Weights:
## IBM GE F MSFT
## 0.25 0.25 0.25 0.25
##
## **************************************************
## PortfolioAnalytics Portfolio Specification
## **************************************************
##
## Call:
## portfolio.spec(assets = colnames(Return))
##
## Number of assets: 4
## Asset Names
## [1] "IBM" "GE" "F" "MSFT"
##
## Constraints
## Enabled constraint types
## - factor_exposure
##
## Objectives:
## Enabled objective names
## - mean
## - StdDev
##
## ****************************************
## Constraints
## ****************************************
## Leverage Constraint:
## min_sum = 1
## max_sum = 1
## actual_leverage = 1
##
## Box Constraints:
## min:
## [1] -Inf -Inf -Inf -Inf
## max:
## [1] Inf Inf Inf Inf
##
## Position Limit Constraints:
## Maximum number of non-zero weights, max_pos:
## [1] "Unconstrained"
## Realized number of non-zero weights (i.e. positions):
## [1] 4
##
## Maximum number of long positions, max_pos_long:
## [1] "Unconstrained"
## Realized number of long positions:
## [1] 3
##
## Maximum number of short positions, max_pos_short:
## [1] "Unconstrained"
## Realized number of short positions:
## [1] 1
##
##
## Diversification Target Constraint:
## [1] "Unconstrained"
##
## Realized diversification:
## [1] 0.5326631
##
## Turnover Target Constraint:
## [1] "Unconstrained"
##
## Realized turnover from initial weights:
## [1] 0.2216893
##
## Factor Exposure Constraints:
## Factor Exposure B Matrix:
## factor1
## IBM.SP500 -1.2658780
## GE.SP500 0.3171101
## F.SP500 -0.1763517
## MSFT.SP500 1.1251196
## attr(,"scaled:center")
## [1] 1.09136
## attr(,"scaled:scale")
## [1] 0.09927187
##
## Lower bound on factor exposures, lower:
## factor1
## 0.0007585556
##
## Upper bound on group weights, upper:
## factor1
## 0.003034222
##
## Realized Factor Exposures:
## factor1
## 0.003034222
##
##
## ****************************************
## Objectives
## ****************************************
##
## Objective: return_objective
## $name
## [1] "mean"
##
## $target
## NULL
##
## $arguments
## list()
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] -1
##
## $call
## add.objective(portfolio = init.portf, type = "return", name = "mean")
##
## attr(,"class")
## [1] "return_objective" "objective"
##
## ****************************************
## Objective: portfolio_risk_objective
## $name
## [1] "StdDev"
##
## $target
## NULL
##
## $arguments
## $arguments$portfolio_method
## [1] "single"
##
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] 1
##
## $call
## add.objective(portfolio = init.portf, type = "risk", name = "StdDev")
##
## attr(,"class")
## [1] "portfolio_risk_objective" "objective"
##
## ****************************************
##
## Elapsed Time:
## Time difference of 0.274622 secs
### Visualize result
library(PerformanceAnalytics)
# Optimal weights
OptWeight = extractWeights(opt.MaxSR)
chart.Weights(opt.MaxSR)
# Sharpe ratio
SharpeRatio(Return, weights = OptWeight, FUN = "StdDev")
## [,1]
## StdDev Sharpe (Rf=0%, p=95%): 0.05439822
# Portfolio returns
PortReturn <- Return.portfolio(R = Return,
weights = OptWeight,
geometric = FALSE) #use arithmetic(FALSE) to aggregate returns
chart.TimeSeries(PortReturn)
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Return = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Return = na.omit(Return[-1,])
colnames(Return)<-Tickers
### Construct Portfolio
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Return))
# Relax the leverage constraint(min_sum = max_sum = 1, by default)
init.portf <- add.constraint(portfolio=init.portf, type="leverage",
min_sum = 0.99, max_sum = 1.01)
# Simplify the optimization problem by setting long only constraint
init.portf <- add.constraint(portfolio=init.portf, type="long_only")
# Add a transaction cost constraint: the transaction cost constraint allows the user to specify proportional transaction costs. Transaction costs are supported as a penalty for the global numeric solvers. Here we add the transaction cost constraint with the proportional transaction cost value of 0.1%
init.portf <- add.constraint(portfolio=init.portf, type="transaction_cost", ptc=0.001)
# Add risk and return objective(we need them to calculate the Sharpe ratio)
init.portf <- add.objective(portfolio=init.portf, type="return", name = "mean")
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "StdDev")
### Solve Portfolio: Maximize Sharpe Ratio
# The default action if “mean” and “StdDev” are specified as objectives with optimize_method="ROI" is to maximize quadratic utility.
# Note that with the ROI solvers, proportional transaction cost constraint is currently only supported for the global minimum variance and quadratic utility problems with ROI quadprog plugin
library(DEoptim)
opt.MaxSR <- optimize.portfolio(R=Return,
portfolio=init.portf,
maxSR=TRUE,
trace=TRUE)
## Iteration: 1 bestvalit: 0.014043 bestmemit: 0.483926 0.030000 0.200000 0.282000
## Iteration: 2 bestvalit: 0.014004 bestmemit: 0.360000 0.134000 0.154000 0.352000
## Iteration: 3 bestvalit: 0.013997 bestmemit: 0.276000 0.098000 0.172000 0.454000
## Iteration: 4 bestvalit: 0.013997 bestmemit: 0.276000 0.098000 0.172000 0.454000
## Iteration: 5 bestvalit: 0.013905 bestmemit: 0.289364 0.163561 0.186120 0.352000
## Iteration: 6 bestvalit: 0.013905 bestmemit: 0.289364 0.163561 0.186120 0.352000
## Iteration: 7 bestvalit: 0.013863 bestmemit: 0.358816 0.094702 0.137990 0.398612
## Iteration: 8 bestvalit: 0.013863 bestmemit: 0.358816 0.094702 0.137990 0.398612
## Iteration: 9 bestvalit: 0.013863 bestmemit: 0.358816 0.094702 0.137990 0.398612
## Iteration: 10 bestvalit: 0.013863 bestmemit: 0.358816 0.094702 0.137990 0.398612
## Iteration: 11 bestvalit: 0.013863 bestmemit: 0.358816 0.094702 0.137990 0.398612
## Iteration: 12 bestvalit: 0.013863 bestmemit: 0.358816 0.094702 0.137990 0.398612
## Iteration: 13 bestvalit: 0.013863 bestmemit: 0.358816 0.094702 0.137990 0.398612
## Iteration: 14 bestvalit: 0.013863 bestmemit: 0.358816 0.094702 0.137990 0.398612
## [1] 0.35881624 0.09470237 0.13799032 0.39861197
summary(opt.MaxSR) # The optimization summary should be read carefully since not every constraint is guaranteed to be satisfied
## **************************************************
## PortfolioAnalytics Optimization Summary
## **************************************************
##
## Call:
## optimize.portfolio(R = Return, portfolio = init.portf, trace = TRUE,
## maxSR = TRUE)
##
## Optimal Weights:
## IBM GE F MSFT
## 0.3588 0.0947 0.1380 0.3986
##
## Objective Measures:
## mean
## 0.0006204
##
##
## StdDev
## 0.01396
##
##
## Portfolio Assets and Initial Weights:
## IBM GE F MSFT
## 0.25 0.25 0.25 0.25
##
## **************************************************
## PortfolioAnalytics Portfolio Specification
## **************************************************
##
## Call:
## portfolio.spec(assets = colnames(Return))
##
## Number of assets: 4
## Asset Names
## [1] "IBM" "GE" "F" "MSFT"
##
## Constraints
## Enabled constraint types
## - leverage
## - long_only
## - transaction_cost
##
## Objectives:
## Enabled objective names
## - mean
## - StdDev
##
## ****************************************
## Constraints
## ****************************************
## Leverage Constraint:
## min_sum = 0.99
## max_sum = 1.01
## actual_leverage = 0.9901209
##
## Box Constraints:
## min:
## IBM GE F MSFT
## 0 0 0 0
## max:
## IBM GE F MSFT
## 1 1 1 1
##
## Position Limit Constraints:
## Maximum number of non-zero weights, max_pos:
## [1] "Unconstrained"
## Realized number of non-zero weights (i.e. positions):
## [1] 4
##
## Maximum number of long positions, max_pos_long:
## [1] "Unconstrained"
## Realized number of long positions:
## [1] 4
##
## Maximum number of short positions, max_pos_short:
## [1] "Unconstrained"
## Realized number of short positions:
## [1] 0
##
##
## Diversification Target Constraint:
## [1] "Unconstrained"
##
## Realized diversification:
## [1] 0.6843495
##
## Turnover Target Constraint:
## [1] "Unconstrained"
##
## Realized turnover from initial weights:
## [1] 0.1311839
##
## ****************************************
## Objectives
## ****************************************
##
## Objective: return_objective
## $name
## [1] "mean"
##
## $target
## NULL
##
## $arguments
## list()
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] -1
##
## $call
## add.objective(portfolio = init.portf, type = "return", name = "mean")
##
## attr(,"class")
## [1] "return_objective" "objective"
##
## ****************************************
## Objective: portfolio_risk_objective
## $name
## [1] "StdDev"
##
## $target
## NULL
##
## $arguments
## $arguments$portfolio_method
## [1] "single"
##
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] 1
##
## $call
## add.objective(portfolio = init.portf, type = "risk", name = "StdDev")
##
## attr(,"class")
## [1] "portfolio_risk_objective" "objective"
##
## ****************************************
##
## Elapsed Time:
## Time difference of 2.183314 secs
### Visualize result
library(PerformanceAnalytics)
# Optimal weights
OptWeight = extractWeights(opt.MaxSR)
chart.Weights(opt.MaxSR)
# Sharpe ratio
SharpeRatio(Return, weights = OptWeight, FUN = "StdDev")
## [,1]
## StdDev Sharpe (Rf=0%, p=95%): 0.04444737
# Portfolio returns
PortReturn <- Return.portfolio(R = Return,
weights = OptWeight,
geometric = FALSE) #use arithmetic(FALSE) to aggregate returns
chart.TimeSeries(PortReturn)
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Return = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Return = na.omit(Return[-1,])
colnames(Return)<-Tickers
### Construct Portfolio
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Return))
# Add a full investment constraint such that the weights sum to 1
init.portf <- add.constraint(portfolio=init.portf, type="full_investment")
# Add risk and return objective(we need them to calculate the Sharpe ratio)
init.portf <- add.objective(portfolio=init.portf, type="return", name = "mean")
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "StdDev")
### Solve Portfolio: Maximize Sharpe Ratio
# The default action if “mean” and “StdDev” are specified as objectives with optimize_method="ROI" is to maximize quadratic utility. If we want to maximize Sharpe Ratio, we need to pass in maxSR=TRUE to optimize.portfolio
library(ROI)
opt.MaxSR <- optimize.portfolio(R=Return,
portfolio=init.portf,
optimize_method="ROI",
maxSR=TRUE,
trace=TRUE)
# Warning: Inf or -Inf values detected in box constraints, maximum return objectives must have finite box constraint values.
summary(opt.MaxSR) # The optimization summary should be read carefully since not every constraint is guaranteed to be satisfied
## **************************************************
## PortfolioAnalytics Optimization Summary
## **************************************************
##
## Call:
## optimize.portfolio(R = Return, portfolio = init.portf, optimize_method = "ROI",
## trace = TRUE, maxSR = TRUE)
##
## Optimal Weights:
## IBM GE F MSFT
## 0.0218 -0.0804 0.0757 0.9830
##
## Objective Measures:
## StdDev
## 0.01733
##
##
## mean
## 0.001288
##
##
## Portfolio Assets and Initial Weights:
## IBM GE F MSFT
## 0.25 0.25 0.25 0.25
##
## **************************************************
## PortfolioAnalytics Portfolio Specification
## **************************************************
##
## Call:
## portfolio.spec(assets = colnames(Return))
##
## Number of assets: 4
## Asset Names
## [1] "IBM" "GE" "F" "MSFT"
##
## Constraints
## Enabled constraint types
## - full_investment
##
## Objectives:
## Enabled objective names
## - mean
## - StdDev
##
## ****************************************
## Constraints
## ****************************************
## Leverage Constraint:
## min_sum = 1
## max_sum = 1
## actual_leverage = 1
##
## Box Constraints:
## min:
## [1] -Inf -Inf -Inf -Inf
## max:
## [1] Inf Inf Inf Inf
##
## Position Limit Constraints:
## Maximum number of non-zero weights, max_pos:
## [1] "Unconstrained"
## Realized number of non-zero weights (i.e. positions):
## [1] 4
##
## Maximum number of long positions, max_pos_long:
## [1] "Unconstrained"
## Realized number of long positions:
## [1] 3
##
## Maximum number of short positions, max_pos_short:
## [1] "Unconstrained"
## Realized number of short positions:
## [1] 1
##
##
## Diversification Target Constraint:
## [1] "Unconstrained"
##
## Realized diversification:
## [1] 0.02113157
##
## Turnover Target Constraint:
## [1] "Unconstrained"
##
## Realized turnover from initial weights:
## [1] 0.3664757
##
## ****************************************
## Objectives
## ****************************************
##
## Objective: return_objective
## $name
## [1] "mean"
##
## $target
## NULL
##
## $arguments
## list()
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] -1
##
## $call
## add.objective(portfolio = init.portf, type = "return", name = "mean")
##
## attr(,"class")
## [1] "return_objective" "objective"
##
## ****************************************
## Objective: portfolio_risk_objective
## $name
## [1] "StdDev"
##
## $target
## NULL
##
## $arguments
## $arguments$portfolio_method
## [1] "single"
##
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] 1
##
## $call
## add.objective(portfolio = init.portf, type = "risk", name = "StdDev")
##
## attr(,"class")
## [1] "portfolio_risk_objective" "objective"
##
## ****************************************
##
## Elapsed Time:
## Time difference of 0.3548465 secs
Caution: The function is called “rebalancing” but the implementation reoptimizes the weights.
### Solve Portfolio: Maximize Sharpe Ratio with Re-balancing
# Quarters rebalancing with 4 year training period and 1 year rolling window
opt.MaxSR.Rebal <- optimize.portfolio.rebalancing(
R = Return,
portfolio = init.portf,
optimize_method = 'ROI',
maxSR=TRUE,
trace = TRUE,
rebalance_on = 'quarters',
training_period = 4*252,
rolling_window = 252)
# Warning: Inf or -Inf values detected in box constraints, maximum return objectives must have finite box constraint values.
summary(opt.MaxSR.Rebal)
## **************************************************
## PortfolioAnalytics Optimization with Rebalancing
## **************************************************
##
## Call:
## optimize.portfolio.rebalancing(R = Return, portfolio = init.portf,
## optimize_method = "ROI", trace = TRUE, maxSR = TRUE, rebalance_on = "quarters",
## training_period = 4 * 252, rolling_window = 252)
##
## First rebalance date:
## [1] "2019-03-29"
##
## Last rebalance date:
## [1] "2021-04-29"
##
## Annualized Portfolio Rebalancing Return:
## [1] 0.3164928
##
## Annualized Portfolio Standard Deviation:
## [1] 0.3560959
##
## Downside Risk Measures:
## portfolio.returns
## Semi Deviation 0.0162
## Gain Deviation 0.0160
## Loss Deviation 0.0178
## Downside Deviation (MAR=210%) 0.0198
## Downside Deviation (Rf=0%) 0.0156
## Downside Deviation (0%) 0.0156
## Maximum Drawdown 0.3053
## Historical VaR (95%) -0.0312
## Historical ES (95%) -0.0519
## Modified VaR (95%) -0.0326
## Modified ES (95%) -0.0546
### Visualize result
library(PerformanceAnalytics)
# Optimal weights
OptWeight = extractWeights(opt.MaxSR)
OptWeight.Rebal = extractWeights(opt.MaxSR.Rebal)
chart.Weights(opt.MaxSR)
chart.Weights(opt.MaxSR.Rebal)
# Portfolio return
PortReturn <- Return.portfolio(R = Return,
weights = OptWeight,
geometric = FALSE) #use arithmetic(FALSE) to aggregate returns
PortReturn.Rebal <- Return.portfolio(R = Return,
weights = OptWeight.Rebal,
geometric = FALSE)
Portfolio.R = cbind(PortReturn,PortReturn.Rebal)
names(Portfolio.R) = c("Non-Rebalancing","Rebalancing")
# First rebalance date: 2019-03-29
charts.PerformanceSummary(Portfolio.R, colors=c("darkred","steelblue"), main=" ")
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Return = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Return = na.omit(Return[-1,])
colnames(Return)<-Tickers
### Construct Portfolio
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Return))
# Add a full investment constraint such that the weights sum to 1
init.portf <- add.constraint(portfolio=init.portf, type="full_investment")
# Add risk and return objective(we need them to calculate the quadratic utility
init.portf <- add.objective(portfolio=init.portf, type="return", name = "mean")
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "var",risk_aversion=.25)
### Solve Portfolio: Maximize Quadratic Utility
# The default action if “mean” and “StdDev” are specified as objectives with optimize_method="ROI" is to maximize quadratic utility.
library(ROI)
opt.MaxQU <- optimize.portfolio(R=Return,
portfolio=init.portf,
optimize_method="ROI",
trace=TRUE)
# Warning: Inf or -Inf values detected in box constraints, maximum return objectives must have finite box constraint values.
summary(opt.MaxQU) #The optimization summary should be read carefully since not every constraint is guaranteed to be satisfied
## **************************************************
## PortfolioAnalytics Optimization Summary
## **************************************************
##
## Call:
## optimize.portfolio(R = Return, portfolio = init.portf, optimize_method = "ROI",
## trace = TRUE)
##
## Optimal Weights:
## IBM GE F MSFT
## -5.3499 -1.7132 -1.0482 9.1113
##
## Objective Measures:
## mean
## 0.01036
##
##
## StdDev
## 0.1406
##
##
## Portfolio Assets and Initial Weights:
## IBM GE F MSFT
## 0.25 0.25 0.25 0.25
##
## **************************************************
## PortfolioAnalytics Portfolio Specification
## **************************************************
##
## Call:
## portfolio.spec(assets = colnames(Return))
##
## Number of assets: 4
## Asset Names
## [1] "IBM" "GE" "F" "MSFT"
##
## Constraints
## Enabled constraint types
## - full_investment
##
## Objectives:
## Enabled objective names
## - mean
## - var
##
## ****************************************
## Constraints
## ****************************************
## Leverage Constraint:
## min_sum = 1
## max_sum = 1
## actual_leverage = 1
##
## Box Constraints:
## min:
## [1] -Inf -Inf -Inf -Inf
## max:
## [1] Inf Inf Inf Inf
##
## Position Limit Constraints:
## Maximum number of non-zero weights, max_pos:
## [1] "Unconstrained"
## Realized number of non-zero weights (i.e. positions):
## [1] 4
##
## Maximum number of long positions, max_pos_long:
## [1] "Unconstrained"
## Realized number of long positions:
## [1] 1
##
## Maximum number of short positions, max_pos_short:
## [1] "Unconstrained"
## Realized number of short positions:
## [1] 3
##
##
## Diversification Target Constraint:
## [1] "Unconstrained"
##
## Realized diversification:
## [1] -114.6706
##
## Turnover Target Constraint:
## [1] "Unconstrained"
##
## Realized turnover from initial weights:
## [1] 4.430642
##
## ****************************************
## Objectives
## ****************************************
##
## Objective: return_objective
## $name
## [1] "mean"
##
## $target
## NULL
##
## $arguments
## list()
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] -1
##
## $call
## add.objective(portfolio = init.portf, type = "return", name = "mean")
##
## attr(,"class")
## [1] "return_objective" "objective"
##
## ****************************************
## Objective: portfolio_risk_objective
## $name
## [1] "var"
##
## $target
## NULL
##
## $arguments
## $arguments$portfolio_method
## [1] "single"
##
##
## $enabled
## [1] TRUE
##
## $multiplier
## [1] 1
##
## $risk_aversion
## [1] 0.25
##
## $call
## add.objective(portfolio = init.portf, type = "risk", name = "var",
## risk_aversion = 0.25)
##
## attr(,"class")
## [1] "portfolio_risk_objective" "objective"
##
## ****************************************
##
## Elapsed Time:
## Time difference of 0.009822369 secs
### Visualize result
library(PerformanceAnalytics)
# Optimal weights
OptWeight = extractWeights(opt.MaxQU)
sum(OptWeight)
## [1] 1
chart.Weights(opt.MaxQU)
# Sharpe ratio
SharpeRatio(Return, weights = OptWeight, FUN = "StdDev")
## [,1]
## StdDev Sharpe (Rf=0%, p=95%): 0.07368932
# Portfolio return
PortReturn <- Return.portfolio(R = Return,
weights = OptWeight,
geometric = FALSE) #use arithmetic(FALSE) to aggregate returns
chart.TimeSeries(PortReturn)
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
### Load Data
library(quantmod)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
### Compute Returns
Return = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Return = na.omit(Return[-1,])
colnames(Return)<-Tickers
# Create the portfolio specification
library(PortfolioAnalytics)
init.portf <-portfolio.spec(assets = colnames(Return))
# Add a full investment constraint such that the weights sum to 1
init.portf <- add.constraint(portfolio=init.portf, type="full_investment")
# Add risk and return objective(we need them to calculate the Sharpe ratio
init.portf <- add.objective(portfolio=init.portf, type="return", name = "mean")
init.portf <- add.objective(portfolio=init.portf, type="risk", name = "StdDev")
### Efficient Frontier
MeanSd.EF <- create.EfficientFrontier(
R = Return,
portfolio = init.portf,
type = "mean-sd",
n.portfolios = 50)
summary(MeanSd.EF)
## **************************************************
## PortfolioAnalytics Efficient Frontier
## **************************************************
##
## Call:
## create.EfficientFrontier(R = Return, portfolio = init.portf,
## type = "mean-sd", n.portfolios = 50)
##
## Efficient Frontier Points: 50
##
## Weights along the efficient frontier:
## IBM GE F MSFT
## 1 0.443 0.048 0.164 0.345
## 2 0.434 0.045 0.162 0.358
## 3 0.426 0.042 0.160 0.371
## 4 0.417 0.040 0.158 0.384
## 5 0.409 0.037 0.157 0.398
## 6 0.400 0.035 0.155 0.411
## 7 0.391 0.032 0.153 0.424
## 8 0.383 0.029 0.151 0.437
## 9 0.374 0.027 0.149 0.450
## 10 0.366 0.024 0.148 0.463
## 11 0.357 0.021 0.146 0.476
## 12 0.348 0.019 0.144 0.489
## 13 0.340 0.016 0.142 0.502
## 14 0.331 0.014 0.140 0.515
## 15 0.323 0.011 0.139 0.528
## 16 0.314 0.008 0.137 0.541
## 17 0.306 0.006 0.135 0.554
## 18 0.297 0.003 0.133 0.567
## 19 0.288 0.001 0.131 0.580
## 20 0.280 -0.002 0.130 0.593
## 21 0.271 -0.005 0.128 0.606
## 22 0.263 -0.007 0.126 0.619
## 23 0.254 -0.010 0.124 0.632
## 24 0.245 -0.012 0.122 0.645
## 25 0.237 -0.015 0.121 0.658
## 26 0.228 -0.018 0.119 0.671
## 27 0.220 -0.020 0.117 0.684
## 28 0.211 -0.023 0.115 0.697
## 29 0.202 -0.026 0.113 0.710
## 30 0.194 -0.028 0.112 0.723
## 31 0.185 -0.031 0.110 0.736
## 32 0.177 -0.033 0.108 0.749
## 33 0.168 -0.036 0.106 0.762
## 34 0.159 -0.039 0.104 0.775
## 35 0.151 -0.041 0.103 0.788
## 36 0.142 -0.044 0.101 0.801
## 37 0.134 -0.046 0.099 0.814
## 38 0.125 -0.049 0.097 0.827
## 39 0.116 -0.052 0.095 0.840
## 40 0.108 -0.054 0.094 0.853
## 41 0.099 -0.057 0.092 0.866
## 42 0.091 -0.060 0.090 0.879
## 43 0.082 -0.062 0.088 0.892
## 44 0.073 -0.065 0.086 0.905
## 45 0.065 -0.067 0.085 0.918
## 46 0.056 -0.070 0.083 0.931
## 47 0.048 -0.073 0.081 0.944
## 48 0.039 -0.075 0.079 0.957
## 49 0.030 -0.078 0.078 0.970
## 50 0.022 -0.080 0.076 0.983
##
## Risk and return metrics along the efficient frontier:
## mean StdDev out
## 1 0.001 0.014 0
## 2 0.001 0.014 0
## 3 0.001 0.014 0
## 4 0.001 0.014 0
## 5 0.001 0.014 0
## 6 0.001 0.014 0
## 7 0.001 0.014 0
## 8 0.001 0.014 0
## 9 0.001 0.014 0
## 10 0.001 0.014 0
## 11 0.001 0.014 0
## 12 0.001 0.014 0
## 13 0.001 0.014 0
## 14 0.001 0.014 0
## 15 0.001 0.014 0
## 16 0.001 0.014 0
## 17 0.001 0.014 0
## 18 0.001 0.014 0
## 19 0.001 0.015 0
## 20 0.001 0.015 0
## 21 0.001 0.015 0
## 22 0.001 0.015 0
## 23 0.001 0.015 0
## 24 0.001 0.015 0
## 25 0.001 0.015 0
## 26 0.001 0.015 0
## 27 0.001 0.015 0
## 28 0.001 0.015 0
## 29 0.001 0.015 0
## 30 0.001 0.015 0
## 31 0.001 0.015 0
## 32 0.001 0.015 0
## 33 0.001 0.016 0
## 34 0.001 0.016 0
## 35 0.001 0.016 0
## 36 0.001 0.016 0
## 37 0.001 0.016 0
## 38 0.001 0.016 0
## 39 0.001 0.016 0
## 40 0.001 0.016 0
## 41 0.001 0.016 0
## 42 0.001 0.016 0
## 43 0.001 0.017 0
## 44 0.001 0.017 0
## 45 0.001 0.017 0
## 46 0.001 0.017 0
## 47 0.001 0.017 0
## 48 0.001 0.017 0
## 49 0.001 0.017 0
## 50 0.001 0.017 0
# Plot
chart.EfficientFrontier(MeanSd.EF,
match.col="StdDev", # which column to use for risk
RAR.text="Sharpe Ratio", # string name for risk adjusted return text
rf=0, # risk free rate
tangent.line = TRUE,
type="l", # plot line type
chart.assets=TRUE,
labels.assets=TRUE)
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PerformanceAnalytics)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
#Calculate mean returns and covariance
MeanRet <- sapply(Returns,FUN=mean)
CovRet <- cov(Returns)
#Set expected returns 5% lower than historical avg.
ExpRet <- MeanRet*(1-.05)
#Set variances 5% higher, but covariances the same
ScaledVar <- diag(CovRet)*1.05
ExpCov <- CovRet
diag(ExpCov) <-ScaledVar
#install.packages("IntroCompFinR", repos="http://R-Forge.R-project.org")
library(IntroCompFinR)
# Minimize expected variance subject to target return(long only)
Target <- mean(MeanRet)
opt.MinVar <- efficient.portfolio(er = ExpRet,
cov.mat = ExpCov,
target.return = Target,
shorts = FALSE)
opt.MinVar
## Call:
## efficient.portfolio(er = ExpRet, cov.mat = ExpCov, target.return = Target,
## shorts = FALSE)
##
## Portfolio expected return: 0.0004270109
## Portfolio standard deviation: 0.01432522
## Portfolio weights:
## IBM GE F MSFT
## 0.5049 0.0795 0.1820 0.2336
barplot(opt.MinVar$weights,las=2,cex.name=.6,main="Min Variance Weights",ylim=c(0,.5))
Return.MinVar <- Return.portfolio(R=Returns, weights=opt.MinVar$weights, geometric=F)
charts.PerformanceSummary(Return.MinVar)
### Housekeeping
rm(list=ls()) # clear workspace
cat("\014") # clear console
library(quantmod)
library(PerformanceAnalytics)
startd = "2015-01-01"
endd = "2021-04-30"
Tickers = c("IBM","GE","F","MSFT")
getSymbols(Tickers,from=startd,to=endd,src='yahoo')
## [1] "IBM" "GE" "F" "MSFT"
Returns = do.call(merge,lapply(Tickers, function(x)
periodReturn(Ad(get(x)),period='daily',type='arithmetic')))
Returns = na.omit(Returns[-1,])
colnames(Returns)<-Tickers
#Calculate mean returns and covariance
MeanRet <- sapply(Returns,FUN=mean)
CovRet <- cov(Returns)
#Set expected returns 5% lower than historical avg.
ExpRet <- MeanRet*(1-.05)
#Set variances 5% higher, but covariances the same
ScaledVar <- diag(CovRet)*1.05
ExpCov <- CovRet
diag(ExpCov) <-ScaledVar
#install.packages("IntroCompFinR", repos="http://R-Forge.R-project.org")
library(IntroCompFinR)
# Maximize expected Sharpe Ratio
ExpRiskFree <- 0.75/100/30 # should match the return data frequency
opt.MaxSR <- tangency.portfolio(er = ExpRet,
cov.mat = ExpCov,
risk.free = ExpRiskFree,
shorts = FALSE)
opt.MaxSR
## Call:
## tangency.portfolio(er = ExpRet, cov.mat = ExpCov, risk.free = ExpRiskFree,
## shorts = FALSE)
##
## Portfolio expected return: 0.001223585
## Portfolio standard deviation: 0.01784839
## Portfolio weights:
## IBM GE F MSFT
## 0 0 0 1
barplot(opt.MaxSR$weights,las=2,cex.name=.6,main="Max Sharpe Ratio Weights",ylim=c(0,.5))
Return.MaxSR <- Return.portfolio(R=Returns, weights=opt.MaxSR$weights, geometric=F)
charts.PerformanceSummary(Return.MaxSR)